What message should the MFC dialog control receive before I can modify it

mfc

I have a custom MFC dialog CMyDialog, with a custom control of type CMyControl added using the resource editor – the dialog has a member variable for the control and has DDX set up.

The control is receiving paint messages, and has a custom on-paint handler. But I want to have the equivalent of OnInitDialog in the control, so it can safely do some initialisation when created – putting the code in the constructor leads to problems.
I tried to add handlers for WM_CREATE, WM_NCCREATE messages, and adding overrides to CWnd::Create… but none of these are firing.

What should I watching for, to know it's safe to edit stuff?

Best Answer

Dialog controls are attached to the MFC object when subclassed, after their creation. When WM_CREATE is sent, the control is not yet attached to your object and you don't get the message. You can override PreSubclassWindow to perform needed initialization when the control is subclassed. This will be called during MFC's handling of WM_INITDIALOG.

Related Topic