This is my first MFC application away from VC6, and I feel a little bit stupid:
How do I add the OnInitDialog handler? (I know how to add it manually, but that's a pain in the long run).
double-clicking the dialog - nothing. right click the dialog - "add event handler" is disabled. Properties - Messages has "normal" messages, but not WM_INITDIALOG Properties - Events only holds notifications from contained controls right-clicking in class view - "Add.." only has functions and variables
scratches head
[edit] d'oh - it's a virtual function in MFC, but still...
It appears that you don't even have to open the header file and mess around placing the cursor... After creatingthe class, select the class in the ClassView pane and you can change overrides/messages/events in the Property pane as described above.
Don't feel stupid, it took me forever to figure this out when I first moved from VC6 to VS2008!
Anyway, and also for my own reference, here are the complete steps for adding a dialog box and overriding the
OnInitDialog
method:IDD_MYDIALOG
.CMyDialog
, selectCDialog
as the base class, then press Finish. This will create files namedMyDialog.cpp
andMyDialog.h
and add them to your project.To override the
OnInitDialog
method in theCMyDialog
class:MyDialog.h
.class CMyDialog : public CDialog
. (The top of the Properties window should show "CMyDialog VCCodeClass" - this is important, because the Properties window is highly context sensitive, and you get different options depending on the location of the cursor in the editor.)OnInitDialog
.CMyDialog::OnInitDialog
function.I hope this helps!