
Introduction
This application describes how to broadcast a message to multiple instance of an
application using
SendMessageNotify API.
Details
Follow the following steps to broadcast message
:-
- Register the message function and get its id using
RegisterWindowMessage
API. This function will return a unique id for the message if the registration is success
UINT WM_MYMESSAGE = RegisterWindowMessage("OnTestMyMessage");
- Add the message function in the message map using
ON_REGISTERED_MESSAGE instead of
ON_MESSAGE
BEGIN_MESSAGE_MAP(CTestFindWindowDlg, CDialog)
ON_REGISTERED_MESSAGE(WM_MYMESSAGE,OnTestMyMessage)
END_MESSAGE_MAP()
- Broadcast the message using ::SendNotifyMessage API
BOOL a = ::SendNotifyMessage(HWND_BROADCAST, WM_MYMESSAGE,0,1000);
- Function declaration and definition
afx_msg void OnTestMyMessage(WPARAM wParam,LPARAM lParam);
void CTestFindWindowDlg::OnTestMyMessage(WPARAM wParam,LPARAM lParam)
{
int a =(int)lParam;
CString strValue;
strValue.Format("%d",a);
AfxMessageBox("Broadcast :"+strValue);
}
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here