Anyway, and also for my own reference, here are the complete steps for adding a dialog box and overriding the OnInitDialog
method:
- Select Resource View and expand the .rc file.
- Right-click the Dialog entry in the tree view and select Insert Dialog.
- Select the Properties window. (Note: If you don't see this window, select the View > Other Windows > Properties Window menu item.)
- In the Properties window, set the ID for the dialog, e.g.,
IDD_MYDIALOG
. - Right click the dialog in the resource editor and select Add Class. Note: if you have IE8 installed, this may produce an Internet Explorer Script Error. See this blog post for details on how to correct this.
- In the MFC Class Wizard dialog box, enter the class name, e.g.,
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 the CMyDialog
class:
- Open the file
MyDialog.h
. - Select the Properties window.
- Place the cursor on the line that reads
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.) - Click the Overrides icon in the Properties window.
- Scroll down the properties window to find
OnInitDialog
. - Click the down arrow against this entry and select <Add> OnInitDialog. This should create your
CMyDialog::OnInitDialog
function.
I hope this helps!
出处:http://stackoverflow.com/questions/961617/vs-2008-mfc-add-oninitdialog-how