Click here to Skip to main content
15,890,557 members
Articles / Programming Languages / C++
Article

Broadcast a message to multiple instances of an application

Rate me:
Please Sign up or sign in to vote.
2.19/5 (10 votes)
30 Jun 2004 46.5K   1.4K   20   3
Broadcast a message to multiple instances of an application

Image 1

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)
     // Use ON_REGISTERED_MESSAGE macro instead of ON_MESSAGE
     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
    // .h
    afx_msg void OnTestMyMessage(WPARAM wParam,LPARAM lParam);
    
    //.cpp
    void CTestFindWindowDlg::OnTestMyMessage(WPARAM wParam,LPARAM lParam)
    {
       int a  =(int)lParam;
       CString strValue;
       strValue.Format("%d",a);
       AfxMessageBox("Broadcast :"+strValue);
    }

License

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


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionbroadcast message to multiple users Pin
svknair12-Aug-11 3:07
svknair12-Aug-11 3:07 
i need to broadcast message from text box to a group of users in asp.net how do i do it , wht functionality needs to be used
Questionasp.net broadcast Pin
kiran_05_09_199027-Sep-08 4:46
kiran_05_09_199027-Sep-08 4:46 
GeneralThis is good, but ... Pin
WREY2-Jul-04 8:36
WREY2-Jul-04 8:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.