如何在MFC中使用SendMessage()处理两个对话框项之间的消息? [英] How to handle message in between two dialog items using SendMessage() in MFC?

查看:193
本文介绍了如何在MFC中使用SendMessage()处理两个对话框项之间的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的你好,
实际上,我在应用程序中同时拥有两个对话框和两个文本框.我想要在第二个对话框的文本框中编写的任何内容,都应通过单击按钮将其显示在第一个对话框的文本框中.第二个对话框.
我确定,可以使用"SendMessage()"或"PostMessage()"来实现.

但是现在我失败了,如何获取第一个对话框的文本框句柄,我们需要在第二个对话框中将SendMessage()作为参数传递'' s源代码.

请尽快帮助我.谢谢

解决方案

您可以通过运行该节目的CWinApp进行操作...他拥有指向所有人的指针,因此您可以将句柄作为初始化的一部分传递给任一对话框.

CWinApp()中的某个位置:

CDialog1 dialog1;
CDialog2 dialog2;

dialog1.mp_other_dialog = &dialog2;
dialog2.mp_other_dialog = &dialog1;


其中:
CDialog1CDialog2源自CDialog.
和:
CDialog* mp_other_dialog;

另外,您还可以在任何父类(同样可以使用CWinApp)中创建一个方法,该方法将返回请求的指针.例如:

CWinApp *theApp;
CDialog* dialog = theApp->GetDialog(TYPE);


您可以在第一个对话框中使用"SendMessage()",在第二个对话框中使用"OnReceiveMessage".

Hello dear,
Actually i''m having two dialogs in my application along with a Text Field in both.And i want any thing i wrote in 2nd dialog''s textbox ,it should display in 1st dialog''s text box through a button click in 2nd Dialogbox.
I''m sure,it can possible using either "SendMessage()" OR "PostMessage()" .

But now i''m failing , how to get the handle of 1st Dialog''s Textbox which we need to pass in SendMessage() as parameter in 2nd Dialog''s sourcecode.

Kindly Please help me soon.Thanks

解决方案

You can simply do it through the CWinApp that runs the show... He has the pointers to everyone, so you can just pass the handle to either dialog as part of the initialization.

Somewhere in CWinApp():

CDialog1 dialog1;
CDialog2 dialog2;

dialog1.mp_other_dialog = &dialog2;
dialog2.mp_other_dialog = &dialog1;


where:
CDialog1 and CDialog2 are derived from CDialog.
and:
CDialog* mp_other_dialog;

Alternatively, you can also make a method in whatever parent class (again, CWinApp could be used) that will return a requested pointer. For example:

CWinApp *theApp;
CDialog* dialog = theApp->GetDialog(TYPE);


You can use "SendMessage()" in the 1st dialog an d "OnReceiveMessage" in the 2nd dialog..


这篇关于如何在MFC中使用SendMessage()处理两个对话框项之间的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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