MFC>将对话框连接到对话框类 [英] MFC> Connecting a dialog to a dialog class

查看:210
本文介绍了MFC>将对话框连接到对话框类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在一个已经存在的资源文件中定义了一个新的对话框及其控件。我还创建了一个新文件,它将处理从此对话框生成的事件。但我不知道如何连接这两个。

I have defined a new dialog and its controls in an already existing resource file. I have also created a new file which will handle the events being generated from this dialog. But I am not sure how to connect these two.

语句枚举{IDD = IDD_NEW_DIALOG}; 连接两个所需的所有内容?或者我们应该添加一些其他语句?

Is the statement enum { IDD=IDD_NEW_DIALOG }; all that is required to connect the two? Or should we add some other statement?

推荐答案

通常在MFC中完成的方式是在资源中定义一个对话框模板编辑器(如你所做的),然后在C ++中从CDialog派生一个类,并将其与对话框模板相关联(这听起来像你已经完成了 - 这不完全清楚)。

The way this is usually done in MFC is to define a dialog template in the resource editor (as you've done), then in C++ derive a class from CDialog and associate it with the dialog template (which it sounds like you've done - it's not entirely clear).

这两个实际关联的是CDialog代码的构造函数。如果您看到由MFC类向导自动生成的对话框相关代码,您将在构造函数实现中看到如下所示:

What actually associates the two is the constructor for your CDialog code. If you look at dialog related code auto-generated by the MFC class wizard, you'll see in the constructor implementation something like this:

CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/) : CDialog(CMyDlg::IDD, pParent)

其中CMyDlg :: IDD被定义为具有新对话框模板标识符值的枚举。正是这样才能发生,而不是枚举的声明。您可以将其修改为

where CMyDlg::IDD is defined as an enumeration with a value of your new dialog template's identifier. It's this that makes it all happen, not the declaration of the enum. You could modify it to

CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/) : CDialog(IDD_NEW_DIALOG, pParent)

,它仍然可以工作(假设IDD_NEW_DIALOG是资源中对话框的模板ID)正如所有发生的一样,对话框id被传递到构造函数中。

and it will still work (assuming IDD_NEW_DIALOG is the template id of your dialog in the resources), as all that's happening is the dialog id is being passed into the constructor.

一般来说,总是值得记住的是,尽管初次出现,MFC并没有绑定到Windows编译器的魔法 - 这一切都用C ++和一些宏完成。

In general, it's always worth remembering that, despite initial appearances, MFC does not bind to Windows through bits of compiler magic - it's all done with C++ and a few macros.

编辑:DIALOGEX和DIALOG声明Windows理解的对话框资源格式稍微差异:前者比后者。但是至少从Windows 95起就已经出现了,所以这并不是非常重要的区别。

DIALOGEX and DIALOG declare slightly difference dialog resource formats that Windows understands: the former is newer than the latter. However both have been around since at least Windows 95, so it's not a very significant distinction.

这篇关于MFC>将对话框连接到对话框类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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