vc ++中的多个对话框 [英] multiple dialog in vc++

查看:89
本文介绍了vc ++中的多个对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在使用VC ++ 6.0 [基于MFC].我需要创建多个对话框,以使所有对话框同时处于活动状态.
使用无模式对话方法可以做到这一点吗?
如有可能,请以我为初学者的方式帮助我进行创建,并逐步说明操作步骤.

在此先感谢
vandana

hello,

I am using VC++6.0 [MFC based].I need to create multiple dialogs so that all the dialogs are active simultaneously.
Is this possible to do using modeless dialog method.
If possible please help me in creating and also explain the procedure in steps as I am a beginner.

Thanks in Advance
vandana

推荐答案

Nitheesh George答案几乎是正确的.您只需要动态创建对话框对象,或使其成为类的成员,否则退出该函数后,该对话框对象将被销毁.

如果您希望动态创建对话框,则可以执行以下操作:
Nitheesh George answer is almost correct. You just need to create the dialog object dynamically, or make it member of a class, otherwise the dialog object will be detroyed as soon as you exit the function.

If you prefere to create the dialog dynamically, you can do something like:
CYourDialog* dlg = new CYourDialog();
dlg->Create(IDD_YOUR_DIALOG_ID, this);
dlg->ShowWindow(SW_NORMAL);



为了确保没有内存泄漏,一旦不再需要创建的对话框,还必须删除它.例如:

将此添加到对话框.h文件中:



And to make sure you don''t have memory leaks, you also have to delete the created dialog once it is not needed anymore. For example:

Add this inside your dialog .h file:

class CYourDialog
{
    ...
protected:
    virtual void PostNcDestroy();
    afx_msg void OnClose();
};


将此添加到对话框.cpp文件中:


Add this inside your dialog .cpp file:

BEGIN_MESSAGE_MAP(CYourDialog, CDialog)
    ...
    ON_WM_CLOSE()
END_MESSAGE_MAP()
...
void CYourDialog::PostNcDestroy()
{
    CDialog::PostNcDestroy();
    delete this;
}
void CYourDialog::OnClose()
{
    CDialog::OnClose();
    DestroyWindow();
}




请在下面找到示例,

CMyDialog dlg;
dlg.Create(IDD_DIALOG1,this);
dlg.ShowWindow(SW_NORMAL);

这将创建一个无模型的窗口,您可以与父窗口或任何其他顶级交互,并创建另一个没有问题的模型/无模式的窗口


希望对您有帮助
Hi,

Please find the sample below,

CMyDialog dlg;
dlg.Create(IDD_DIALOG1, this);
dlg.ShowWindow(SW_NORMAL);

this will create a modelless window you can interact with the parent window or any other top level and create another model/modeless window no probs


Hope this helps


您使用的是MFC还是Win32?
Are you using MFC or just Win32?


这篇关于vc ++中的多个对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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