MFC, Message Reflection, Dialog Template, What's Wrong?
Hi all,
I'm confused with MFC message reflection. I've read TN061-TN062, and I think I understood this mechanism. Well, here is my situation:
Background:
I derived my own control class CMyTreeCtrl from CTreeCtrl, added the necessary entries into the message map of CMyTreeCtrl using the ON_NOTIFY_REFLECT() macro.
Problem:
Yes, my control works perfectly if I create it as a child window of a CView object, or even as a child of a generic CWnd object. Also, if I draw a standard tree control onto the dialog template in the resource editor, and then subclass the control to my own control class with DDX, it looks good.
But, if I create a standard tree control and then subclass it to my own class during runtime, I will not receive the WM_CREATE message. So I have to place the initialization code in WM_INITDIALOG handler. This makes my code ugly, because something must be done and some states must be decided during creation. So I removed the standard one from the dialog template and create a control of my own class "manually" in the WM_CREATE handler of the parent dialog window, as the child of the dialog. I found the message reflection DOES NOT WORK now! Except some notifications like NM_CLICK or TVN_KEYDOWN. The others, for example, TVN_SELCHANGED, TVN_ITEMEXPANDED, do not work.
If I encapsulate my control into a view or even generic CWnd, then create the container window during creation of the parent dialog, message reflection will be available again.
The parent dialog is a modeless dialog.
What's wrong? Why I cannot get the reflected message if I create a control outside the dialog template? What's the differences between a dialog parent and a generic window parent? I will be appreciate if anyone can give me some tips, thank you.