CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Guest

    I want to send messages between 2 windows-applications. What must I do?

    Both applications are written in C++. The first application must send a message and the other application must react if the message is sent. Any help is appreciated.


  2. #2
    Join Date
    Sep 1999
    Location
    Michigan
    Posts
    215

    Re: I want to send messages between 2 windows-applications. What must I do?

    One way to do it is to use the FindWindow() function and post a mutually defined message to the other app.


  3. #3
    Join Date
    Jun 1999
    Posts
    1,786

    Re: I want to send messages between 2 windows-applications. What must I do?

    Here is the sample (not the only way, I guess, but I would use it)

    // 1. In your application-sender:
    UINT Message2Send = ::RegisterWindowMessage("STR_CoolMessage");

    // 2. In your application - receiver:
    UINT Message2Receive = ::RegisterWindowMessage("STR_CoolMessage");

    // Note: the trick is to register messages using EXACTLY THE SAME
    // string in both applications: Windows will return THE SAME value.

    // 3. In your application-sender:
    ::SendMessage(HWND_BROADCAST, Message2Send, (WPARAM)0, (LPARAM)0);
    // This call will send the message for all top-level windows in the system, see Help

    // 4. The rest is to catch and handle the message in application - receiver:
    // In you MainFrame declare function-handler
    afx_msg LRESULT OnCoolMessage(WPARAM WParam, LPARAM LParam);

    // In message map of your MainFrame add this entry
    ON_REGISTERED_MESSAGE(Message2Receive, OnCoolMessage)

    // And add implementation:
    LRESULT CMainFrame::OnCoolMessage(WPARAM WParam, LPARAM LParam)
    {
    AfxMessageBox("COOL!");
    return (LRESULT)0;
    }








  4. #4
    Join Date
    Apr 1999
    Location
    INDIA
    Posts
    36

    Re: I want to send messages between 2 windows-applications. What must I do?

    Hi,

    Use the user defined messages.
    In the first app define a message with WM_USER + ...
    i.e #define WM_MYMSG WM_USER+1
    Same in the second app.

    Handle the messages with appropriate functions.

    Call the SendMessage with ur own MessageHandler
    i.e SendMessage(WM_MYMSG, .......)

    Hope this helps
    Shankar



  5. #5
    Join Date
    Oct 1999
    Posts
    18

    Re: I want to send messages between 2 windows-applications. What must I do?

    Hi. I had tested your code. But did not work between 2 app. What's the prolem ?

    Regards

    ktpark


  6. #6
    Join Date
    Nov 1999
    Posts
    283

    Re: I want to send messages between 2 windows-applications. What must I do?


  7. #7
    Join Date
    Jun 1999
    Posts
    1,786

    Re: I want to send messages between 2 windows-applications. What must I do?

    Hi
    I don't know why, but SendMessage(HWND_BROADCAST, ... ) really doesnt work. You can use PostMessage instead (parameters are the same). I works, I've tested it.


  8. #8
    Join Date
    Oct 1999
    Posts
    18

    Re: I want to send messages between 2 windows-applications. What must I do?

    Hi. Thanks for your response. I got it this problem. See the link below.
    http://codeguru.developer.com/bbs/wt...sb=5&category=

    Thanks for all comments

    Best regards

    ktpark



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured