• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 353
  • Last Modified:

MFC user defined message

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.

1 Solution
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.
JohnSantaFeAuthor Commented:

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.

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now