VS 2008,MFC:添加OnInitDialog - 怎么样? [英] VS 2008, MFC: add OnInitDialog - how?
问题描述
这是我第一个远离VC6的MFC应用程序,我觉得有点愚蠢:
This is my first MFC application away from VC6, and I feel a little bit stupid:
如何添加OnInitDialog处理程序?
(我知道如何手动添加它,但从长远来看这很痛苦。)
How do I add the OnInitDialog handler? (I know how to add it manually, but that's a pain in the long run).
双击对话框 - 没有。
右键单击对话框 - 禁用添加事件处理程序。
属性 - 消息具有正常消息,但不包含WM_INITDIALOG
属性 - 事件仅保存来自包含控件的通知
在类视图中右键单击 - 添加...仅包含函数和变量
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
划伤头
d'oh - 这是一个虚拟功能在MFC中,但仍然......
[edit] d'oh - it's a virtual function in MFC, but still...
推荐答案
不要感到愚蠢,我第一次想到这一点就花了很多时间从VC6移到VS2008!
Don't feel stupid, it took me forever to figure this out when I first moved from VC6 to VS2008!
无论如何,也是为了我自己的参考,这里是添加对话框并覆盖 OnInitDialog的完整步骤
方法:
Anyway, and also for my own reference, here are the complete steps for adding a dialog box and overriding the OnInitDialog
method:
- 选择资源视图并展开.rc文件。
- 右键单击树状视图中的对话框条目,然后选择插入对话框。
- 选择属性窗口。 (注意:如果您没有看到此窗口,请选择查看> 其他Windows > 属性窗口菜单项。)
- 在属性窗口中,设置对话框的ID,例如
IDD_MYDIALOG
。 - 右键单击资源编辑器中的对话框,然后选择添加类。注意:如果安装了IE8,则可能会产生Internet Explorer脚本错误。参见此博客文章有关如何纠正此问题的详细信息。
- 在 MFC类向导对话框中,输入班级名称,例如,
CMyDialog
,选择CDialog
作为基类,然后按完成。这将创建名为MyDialog.cpp
和MyDialog.h
的文件,并将它们添加到您的项目中。
- 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.
覆盖 CMyDialog $ c $中的
OnInitDialog
方法c> class:
To override the OnInitDialog
method in the CMyDialog
class:
- 打开文件
MyDialog.h
。 - 选择属性窗口。
- 将光标放在
类的行上CMyDialog:public CDialog
。 (属性窗口的顶部应显示 CMyDialog VCCodeClass - 这很重要,因为属性窗口具有高度上下文相关性,您可以根据位置获得不同的选项光标在编辑器中。) - 点击属性窗口中的覆盖图标。
- 向下滚动属性窗口以查找
OnInitDialog
。 - 点击此条目的向下箭头,然后选择<添加> OnInitDialog中即可。这应该创建你的
CMyDialog :: OnInitDialog
函数。
- 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.
我希望这有助于!
这篇关于VS 2008,MFC:添加OnInitDialog - 怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!