在两个无模式对话框之间进行通信 [英] Communicating between two modeless dialogs

查看:68
本文介绍了在两个无模式对话框之间进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用按钮复选框来启动无模式对话框.退出时,我想通知父对话框,以便取消选中该复选框.

我已经使用SendMessage与同一对话框中的编辑控件进行通信,但是对话框之间没有任何成功.我获得的在线帮助令人困惑.
我不清楚如何连接管道.

我真正需要的是白痴的入门指南,或者至少是简单的解释.

感谢您提供的所有帮助.

好吧,现在我不在野草中了...消息已发送但未到达我期望的位置.

为了澄清起见,父级有两个子级对话框...两个子级都不需要与另一个子级进行通信,但是它们都需要在退出时通知父级.在单击按钮之前,不会实例化该子对象,因此我无法对其主init进行处理.

这些是弹出式对话框,而不是子对话框,如果有区别的话.

I use a push button check box to initiate a modeless dialog. On exiting I want to to notify the parent dialog so that I can uncheck the check box, among other things.

I''ve used SendMessage to communicate with edit controls within the same dialog, but not having any success between dialogs. The online help I get is confusing.
I can''t get a clear explanation of how to connect the pipes.

What I really need is a guide for idiots to get me started, or at the least a simple explanation.

Thanks for any and all help.

Well, now I''m off in the weeds...message sent but not going where I expect.

To clarify, parent has two child dialogs...neither child needs to communicate with the other, but both need to notify the parent when they exit. The child isn''t instantiated until push button is clicked, so I have no handle on init of my main.

And these are pop-up, not child, dialogs...if that makes a difference.

推荐答案

SendMessage()是CWnd的一部分(尽管也有一个)这是WinAPI的直接组成部分),这意味着任何CWnd派生的类都包含此调用...如果您需要在两个CWnd派生的CDialogs之间进行消息传递,则只需要给它们彼此提供句柄(作为CWnd或CDialog,那么您就可以直接在它们之间发送消息.

说你有...
SendMessage() is part of CWnd (although there is also one that is directly part of WinAPI), meaning any CWnd derived class contains this call... if you need to message between two CDialogs, which are CWnd derived, you just need to give them each others handles, either as CWnd or as CDialog, then you can just message between them directly.

say you have...
CDialog MainDialog;



拥有...



that owns...

CDialog ChildDialog1;
CDialog ChildDialog2;



在MainDialog的构造函数或InitDialog()中...



within either the constructor or InitDialog() of MainDialog...

ChildDialog1.m_hDialog = &ChildDialog2; //where you''ve defined m_hDialog to be either
ChildDialog2.m_hDialog = &ChildDialog1; //  CWnd* or CDialog* (either will work)



现在让他们直接互相发消息,



now for them to message each other directly,

m_hDialog->SendMessage(...); //within either ChildDialog



[edit]
您错过了重点...如果您拥有任何CWnd的句柄,都可以向其发送消息.



[edit]
You''re missing the point... if you have a handle to any CWnd, you can message to it.

//Within main dialog
CMainDialog::OnButtonClick()
{
  COtherDialog Child;
  Child.m_hParent = this;

  Child.DoModal();
}

//Within COtherDialog
COtherDialog::OnButtonClickity()
{
  m_hParent->SendMessage(...);
  ...yada, yada, yada...
 return;
}


[/edit]


[/edit]


这篇关于在两个无模式对话框之间进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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