Get DC of child in CTabCtrl-Collection of common programming errors

Hi all, I have a tab control containing dialogs that I wish to draw on, however I am having inordinate problems working out how to get the correct device context and correct rectangle so that I can draw onto the child windows dynamically based on user input into controls on the child windows themselves. Any calls to GetDC() within the child windows throws up an error at runtime, and I need to be able to get the device context from within the child windows so that they can react to the user input. Does anyone have any ideas how to do this, the internet is reticent in this area. I am using MFC and CTabCtrl. Regards,

IxxI

  1. A couple of points of note:  In MFC items contained in a CTabCtrl are siblings of the tab control, not children.  You are responsible to show/hide the dialogs as the user interacts with the tabs.  Trying to make the dialogs children of the tabs will probably lead to major problems. Assuming that you have created a bunch of CDialogs that correspond with the “client area” of the individual tabs, and you wish to draw directly to the CDialogs, your best bet would be to handle the OnPaint (WM_PAINT) message in the dialogs.  You will be provided with a DC for drawing there.
  2. If the dialog is not calling OnPaint it probably means that you somehow deleted

    ON_WM_PAINT()from the dialog’s message map.There isn’t any good way to paint on a dialog unless you paint the entire background.  It is usually better to put a static control on the dialog and paint on that.

  3. If the dialog is not calling OnPaint it probably means that you somehow deleted

    ON_WM_PAINT()from the dialog’s message map.There isn’t any good way to paint on a dialog unless you paint the entire background.  It is usually better to put a static control on the dialog and paint on that.