⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readme.wzd

📁 E:Visual_C__MFC扩展编程实例 实例49:向其他应用程序发送消息
💻 WZD
字号:
/////////////////////////////////////////////////////////////////////
// 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -