VS 2008, MFC: add OnInitDialog - how?(VS 2008,MFC:添加 OnInitDialog - 如何?)
问题描述
这是我第一个远离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
抓头
[edit] 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 文件.
- 右键单击树视图中的 Dialog 条目,然后选择 Insert Dialog.
- 选择属性窗口.(注意:如果您没有看到此窗口,请选择查看 > 其他窗口 > 属性窗口菜单项.)
- 在 Properties 窗口中,设置对话框的 ID,例如
IDD_MYDIALOG. - 右键单击资源编辑器中的对话框并选择添加类.注意:如果您安装了 IE8,这可能会产生 Internet Explorer 脚本错误.请参阅 这篇博文了解如何更正此问题的详细信息.
- 在MFC Class Wizard对话框中,输入类名,如
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, selectCDialogas the base class, then press Finish. This will create files namedMyDialog.cppandMyDialog.hand add them to your project.
要覆盖 CMyDialog 类中的 OnInitDialog 方法:
To override the OnInitDialog method in the CMyDialog class:
- 打开文件
MyDialog.h. - 选择属性窗口.
- 将光标放在读取
class CMyDialog : public CDialog的行上.(属性窗口的顶部应该显示CMyDialog VCCodeClass" - 这很重要,因为 Properties 窗口对上下文非常敏感,并且您可以根据位置获得不同的选项编辑器中的光标.) - 点击属性窗口中的覆盖图标.
- 向下滚动属性窗口以找到
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::OnInitDialogfunction.
我希望这会有所帮助!
这篇关于VS 2008,MFC:添加 OnInitDialog - 如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:VS 2008,MFC:添加 OnInitDialog - 如何?
基础教程推荐
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
