We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


MFC user defined message

JohnSantaFe asked
Medium Priority
Last Modified: 2008-03-17
I'd like to create a user defined message to have a thread pass a message back to the main MFC application.  

My understanding of how to do this is as follows;

1. Register the message:
static const int WMU_RUN_COMPLETE = RegisterWindowMessage("WMU_RUN_COMPLETE");

2. Declare the function that will eventually handle the message;
afx_msg LRESULT OnRunComplete(WPARAM wParam, LPARAM lParam);

3. Add it to the message map;

4. Register the same message name in my thread;
static const int WMU_RUN_COMPLETE = RegisterWindowMessage("WMU_RUN_COMPLETE");

5. Send the message from my thread;
SendMessage(hwnd, MY_WM_RUN_COMPLETE, (WPARAM)0, (LPARAM)0);

I haven't even gotten to steps 4 and 5 yet.  When I compile, I get an undeclared identifier, WMU_RUN_COMPLETE, because of the reference in the message map.

Where am I supposed to put the WMU_RUN_COMPLETE declaration and RegisterWindowMessage?

Note, this is a dialog based application and not a full document view app.

This is the first time I've tried this, so any other comments would be appreciated.

Watch Question

Place the line
static const int WMU_RUN_COMPLETE = RegisterWindowMessage("WMU_RUN_COMPLETE");

to h-file and include it to every cpp file where it is used.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts



I was trying to declare it as a public member of the clas : {

I moved it up out of the class but still in the .h file and that worked.

Thanks for the tip.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.