tags:

views:

154

answers:

3

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?

A: 

What's the problem in overriding CWnd::Create? You should be able to do it and then first call the parent method (CWnd::Create()) and then do your stuff. But in this case you will have to create the control yourself.

You can also override PreSubclassWindow.

Anyway, a bit more information or some code would nice to understand your problem.

Javier De Pedro
By override of Create is never called.
John
A: 

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.

interjay
A: 
  1. Check your messagemap is set up correctly, and definitely contains WM_CREATE.
  2. Check your OnCreate function signature is declared correctly.
  3. Use ASSERT in your OnCreate instead of a breakpoint
    (maybe it's getting there but skipping the breakpoint)
  4. Try to isolate the problem using a brand new application, then post your code if it still happens.

You might also want to follow some of these tutorials.

demoncodemonkey