MFC User Control Prevents Dialog Creation

I have a custom MFC control, a subclass of CWnd. In addition to providing OnPaint and PreSubclassWindow implementations, it does not override any default functionality and does nothing strange in the design, except registering the window class in the constructor.

The control is added to the dialog using the dialog editor to add a custom control.

The dialog worked when it was a simple modal dialog obtained from CDialog, but we have code that calls CWnd :: CreateDlgIndirect to the instance dialogs, and this fails with a custom control ... but it works if the user control removed from resource template.

+2
source share
1 answer

Found! I had user control registering its window class in my own constructor. I had a member in the dialog of this custom control type, so ctor was called when the dialog was created, as intended. But it turns out that the base class with which I changed the dialog to extract from it instead of CDialog called CreateDlgIndirect in my own ctor before my own initialization of the new class was achieved, so it tried to create its own control before the window class was registered.

My (slightly messy solution) is to register window classes when the application starts in the InitInstance method before any dialog description occurs.

+1
source

All Articles