Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Receiving registered Windows-messages

Posted on 1998-12-18
3
Medium Priority
?
229 Views
Last Modified: 2013-12-03
Hi, I'm trying to make two applications send custom windows-messages to eachother. I have managed registering and sending messages (I've seen the message beeing sent, using SPY), but I can't seem to find out how to receive them :)

Here is some relevant code:

registering..
UINT setSelected =
RegisterWindowMessage("TREE_SELECTION_PERFORMED");

sending..
PostMessage(setSelected, 0, 0);

Now.. how can I detect and apprehend this message from another application? (or even the same one..)

Assert(Christmas == 'Merry!')
0
Comment
Question by:toblo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 120 total points
ID: 1417475
OK

1. the sending code is wrong.  You need to use Send/PostMessage( hWnd, setSelected, 0, 0 ) ; where hWnd is the HWND of the target app, or HWND_BROADCAST.  Use HWND_BROADCAST to do a broadcast to all top level Windows in the system.

2. The top level Window of the receiving apps will  receive this message.  However as the defualt behaviour is to do nothing with non-understood messages, nothing happens.

What you need to do is check for the particular message

In the target app, ALSO register the message, and compare this against the message parameter received in the top level window (you must use if, not switch/case)


3. A tip :
because you probably don't want to overhead of broadcasting messages all the time, it's a good idea to use a hand-shaking protocol :-

App1 -> SendMessage HWND_BROADCAST, with custom message #1, with it's own HWND stuffed into WPARAM

App2 -> Receives custom message #1.  Pulls out WPARAM to get the send, does SendMessage back using custom message #2  to tell App #1 it got it, and it's HWND (which it stuffs into WPARAM)

App1 -> Receives custom message #2.  Unpacks WPARAM.  It now knows who it it communicating with.

At this point both apps know the HWND of the app to talk to, so can do SendMessage with that HWND, rather than doing broadcasts
0
 

Author Comment

by:toblo
ID: 1417476
Hi!

Problem: I still don't know how to receive the message.. should it be done in CTesterDlg::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) ??

 my app is dialog-based, by the way. Just for testing I'm trying to make it both send and retreive the test-message

When I send it, using ::PostMessage(HWND_BROADCAST, MyMessage, 0,0) I can see that it has been sent (using Spy++), but CTesterDlg::OnCmdMsg doesn't seem to react to it at all! -It reacts to my clicking the buttons in the dialog, though..


perplexedly yours :)
/Torbjörn Josefsson

0
 

Author Comment

by:toblo
ID: 1417477

Very useful information, although not all that I needed..
-If anybody else wonders how to receive them custom-messages in MFC:

In the message-map section, do this..
ON_REGISTERED_MESSAGE(MY_VERY_OWN_MESSAGE, OnMyMessage)

(MY_VERY_OWN_MESSAGE is the id I got from RegisterWindowMessage)

Declare it in the .h file as..
afx_msg LRESULT OnMyMessage(WPARAM, LPARAM);

and then just write the OnMyMessage-function (the handler)
Oh.. and you have to use the send/post-method that includes the recipient window (or broadcasts the message)

good luck :)
/Toblo

0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question