从子Windows获取邮件

时间:2014-02-20 13:21:00

标签: mfc

我想从子窗口获取消息。我无法做到。请帮助我。 我想要检索另一个子窗口发送的消息。 这里用户定义的消息是常量510,我在OnGirish()

中处理它

// WndSecond.cpp:实现文件     //

#include "stdafx.h"
#include "DemoB.h"
#include "WndSecond.h"

// #define ID_GIRISH 500
// CWndSecond

IMPLEMENT_DYNAMIC(CWndSecond, CWnd)
//Constructor
CWndSecond::CWndSecond()
{

}
//Destructor
CWndSecond::~CWndSecond()
{
}

//Message map for this window
BEGIN_MESSAGE_MAP(CWndSecond, CWnd)
    ON_WM_PAINT()
    ON_COMMAND(510,OnGirish)
END_MESSAGE_MAP()



// CWndSecond message handlers


BOOL CWndSecond::PreCreateWindow(CREATESTRUCT& cs) 
{
    if (!CWnd::PreCreateWindow(cs))
        return FALSE;

    cs.dwExStyle |= WS_EX_CLIENTEDGE;
    cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
        ::LoadCursor(NULL, IDC_ARROW), CreateSolidBrush(RGB(0,255,0)), NULL);

    return TRUE;
}

void CWndSecond::OnPaint()
{
    CClientDC dc(this);
}

//Handler for retrieving user defined message sent by another window
void CWndSecond::OnGirish()
{
    //Here I want to retrieve the message sent by another child window
    GetMessae(510,0,0);
    MessageBox(_T("Message"), _T("Hello World"),MB_ICONASTERISK|MB_OK); 
}

2 个答案:

答案 0 :(得分:0)

您应该使用RegisterWindowMessage来定义消息。并且,ON_REGISTERED_MESSAGE宏来处理它。

答案 1 :(得分:0)

只有在需要发送进程间消息时才需要RegisterWindowMessage,否则值大于WM_USER / WM_APP的常量就可以了。在MFC应用程序UI线程中,直接调用GetMessage()是“永远”权利。 MFC框架处理消息队列本身并将消息分派给您的窗口。要将消息发送到特定窗口,请使用:: SendMessage或:: PostMessage,并将接收器窗口句柄作为第一个参数,并在消息映射中使用ON_MESSAGE。处理程序LRESULT func(WPARAM,LPARAM);

的原型
相关问题