Click here to Skip to main content
Licence 
First Posted 30 Jun 2004
Views 27,467
Downloads 819
Bookmarked 17 times

Broadcast a message to multiple instances of an application

By | 30 Jun 2004 | Article
Broadcast a message to multiple instances of an application

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

About the Author

bijua2001



India India

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questionbroadcast message to multiple users Pinmembersvknair3:07 12 Aug '11  
Questionasp.net broadcast Pinmemberkiran_05_09_19904:46 27 Sep '08  
GeneralThis is good, but ... PinmemberWREY8:36 2 Jul '04  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 1 Jul 2004
Article Copyright 2004 by bijua2001
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid