readme.wzd

来自「MFC扩展编程实例」· WZD 代码 · 共 67 行

WZD
67
字号
/////////////////////////////////////////////////////////////////////
// to send a registered message
/////////////////////////////////////////////////////////////////////

// 1) define message id and create static variable to hold assigned id
#define HELLO_MSG "{6047CCB1-E4E7-11d1-9B7E-00AAD03D9695}"
UINT	idHelloMsg;

// 2) register message in class's constructor
	idHelloMsg=::RegisterWindowMessage(HELLO_MSG);

// 3) send the message
	WPARAM wParam=(WPARAM)m_hWnd;
	LPARAM lParam=0;
	::SendMessage(m_hOtherWnd,idHelloMsg,wParam,lParam);

/////////////////////////////////////////////////////////////////////
// to receive a registered message
/////////////////////////////////////////////////////////////////////

// 1) declare a message handler in a class's include file
protected:
	//{{AFX_MSG(CMainFrame)
	//}}AFX_MSG
	LRESULT OnHelloMsg(WPARAM wParam,LPARAM lParam);
	DECLARE_MESSAGE_MAP()


// 2) add the handler to a class's message map
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	//}}AFX_MSG_MAP
	ON_REGISTERED_MESSAGE(idHelloMsg,OnHelloMsg) <<<
END_MESSAGE_MAP()

// 3) implement the message handler
LRESULT CMainFrame::OnHelloMsg(WPARAM wParam,LPARAM lParam)
{
	return 0;
}

// to send a message to another application
	idReplyMsg=::RegisterWindowMessage(REPLY_MSG);
	WPARAM wParam=(WPARAM)m_hWnd;
	LPARAM lParam=0;
	::SendMessage(m_hOtherWnd,idReplyMsg,wParam,lParam);

/////////////////////////////////////////////////////////////////////
// to broadcast a registered message
/////////////////////////////////////////////////////////////////////

// 1) register the message as above

// 2) to broadcast the message to all other applications running
	WPARAM wParam=(WPARAM)m_hWnd;
	LPARAM lParam=0;
	DWORD dwRecipients=BSM_APPLICATIONS;
	::BroadcastSystemMessage(BSF_IGNORECURRENTTASK,&dwRecipients,idHelloMsg,wParam,lParam);

// 3) receive this message as above

/////////////////////////////////////////////////////////////////////
// From: Visual C++ MFC Programming by Example by John E. Swanke
// Copyright (C) 1999 jeswanke. All rights reserved.
/////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?