VS 2008,MFC:添加OnInitDialog - 怎么样? [英] VS 2008, MFC: add OnInitDialog - how?

查看:408
本文介绍了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

划伤头

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:


  1. 选择资源视图并展开.rc文件。

  2. 右键单击树状视图中的对话框条目,然后选择插入对话框

  3. 选择属性窗口。 (注意:如果您没有看到此窗口,请选择查看> 其他Windows > 属性窗口菜单项。)

  4. 属性窗口中,设置对话框的ID,例如 IDD_MYDIALOG

  5. 右键单击资源编辑器中的对话框,然后选择添加类。注意:如果安装了IE8,则可能会产生Internet Explorer脚本错误。参见此博客文章有关如何纠正此问题的详细信息。

  6. MFC类向导对话框中,输入班级名称,例如, CMyDialog ,选择 CDialog 作为基类,然后按完成。这将创建名为 MyDialog.cpp MyDialog.h 的文件,并将它们添加到您的项目中。

  1. Select Resource View and expand the .rc file.
  2. Right-click the Dialog entry in the tree view and select Insert Dialog.
  3. Select the Properties window. (Note: If you don't see this window, select the View > Other Windows > Properties Window menu item.)
  4. In the Properties window, set the ID for the dialog, e.g., IDD_MYDIALOG.
  5. 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.
  6. In the MFC Class Wizard dialog box, enter the class name, e.g., CMyDialog, select CDialog as the base class, then press Finish. This will create files named MyDialog.cpp and MyDialog.h and add them to your project.

覆盖 CMyDialog OnInitDialog 方法c> class:

To override the OnInitDialog method in the CMyDialog class:


  1. 打开文件 MyDialog.h

  2. 选择属性窗口。

  3. 将光标放在类的行上CMyDialog:public CDialog 。 (属性窗口的顶部应显示 CMyDialog VCCodeClass - 这很重要,因为属性窗口具有高度上下文相关性,您可以根据位置获得不同的选项光标在编辑器中。)

  4. 点击属性窗口中的覆盖图标。

  5. 向下滚动属性窗口以查找 OnInitDialog

  6. 点击此条目的向下箭头,然后选择<添加> OnInitDialog中即可。这应该创建你的 CMyDialog :: OnInitDialog 函数。

  1. Open the file MyDialog.h.
  2. Select the Properties window.
  3. 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.)
  4. Click the Overrides icon in the Properties window.
  5. Scroll down the properties window to find OnInitDialog.
  6. Click the down arrow against this entry and select <Add> OnInitDialog. This should create your CMyDialog::OnInitDialog function.

我希望这有助于!

这篇关于VS 2008,MFC:添加OnInitDialog - 怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆