如何在MFC中从另一个对话框(通过单击按钮)打开一个对话框? [英] How to open a dialog from another dialog (by button click) in MFC ?

查看:209
本文介绍了如何在MFC中从另一个对话框(通过单击按钮)打开一个对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我必须在VS6.0的MFC中制作一个GUI.
我要实现以下行为:
当我按下按钮时,另一个对话框窗口应该打开.
另外,当通过单击按钮打开第二个窗口时,我们如何隐藏/关闭第一个窗口?

请回复..如果可能的话,然后进行演示..
我的ID:[电子邮件地址已删除]
:)

Hi,
I have to make a GUI in VS6.0 in MFC.
I want to implement the following behaviour:
When I press button another dialog window should be open.
Also how can we hide/close first window when second is open by clicking on button?

Please reply.. if possible then with demo..
my id: [e-mail address removed]
:)

推荐答案

您的子对话框类成员函数"OnInitDialog"中的这一行将隐藏父对话框.

This line in your child dialog class member function "OnInitDialog" will hide the parent dialog.

<br />
GetOwner()->ShowWindow( FALSE );<br />



如果要在关闭子对话框的情况下返回父对话框,则必须在子窗口类中添加关闭消息处理程序,并在此行中添加该功能:



if you want to bring the parent dialog back in case of closing the child dialog, so you have to add closing message handler in your child window class, and add that function this line:

<br />
GetOwner()->ShowWindow( TRUE );<br />


我会同意CPAllini的响应并进行调整.

I would concur with CPAllini''s response with an adjustment.

CPallini写道:
CPallini wrote:

假设您的对话框有一个父窗口,那么在单击按钮时,您应该:

1.通知父窗口应该打开另一个对话框(例如,可以设置一个标志).
2.关闭当前对话框.

Assuming your dialog has a parent window, then, on button click, you should:

1. Notify to the parent window that the other dialog should be open (you may set a flag, for instance).
2. Close the current dialog.



但是,我不会设置标志来通知父窗口.相反,我会:

1)向父母发送一个窗口的消息.这要求您使用自定义的Windows消息并在父级中为其实现处理程序.



2)调用父对话框对象的方法.这要求先前为子对话框提供了正确键入的引用或指向父对话框的指针.

我更喜欢选项1,因为它似乎在类之间并不需要那么多的耦合.


如果您确实选择了Jast_in的答案,请确保确实注意&的确切时间.您将如何看待隐藏的窗口被重新显示或关闭.



I would not, however, set a flag to notify the parent window. Instead I would either:

1) Send the parent a Window''s message. This requires you to use a custom windows message and implement a handler for it in the parent.

or

2) Call a method of the parent dialog''s object. This requires that the child dialog was previously provided with a properly typed reference or pointer to the parent dialog.

I would prefer option 1 as it does not seem to require as quite as much coupling between the classes.


If you do opt for Jast_in''s answer, make sure you do pay attention to exactly when & how you will see that the hidden window gets redisplayed or closed.


也许我不明白您到底需要实现什么.
如果显示/隐藏"与您的父应用程序有关,那么我的第一篇文章将起作用.如果由于按下按钮而仅将显示/隐藏"连接到对话框打开,则必须保持打开的对话框以隐藏对话框.
然后,ShowWindow(BOOL)将可以正常工作.
Maybe I didn''t understand what you need to implement exactly.
If "show/hide" is about your parent application then my first post will work. If "show/hide" connected only to dialogs open due to button pressing then you have to keep open dialog to make the dialog hide.
Then ShowWindow(BOOL) will work surely.


这篇关于如何在MFC中从另一个对话框(通过单击按钮)打开一个对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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