• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 370
  • 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;
ON_REGISTERED_MESSAGE (WMU_RUN_COMPLETE, OnRunComplete)

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.

Thanks.
0
JohnSantaFe
Asked:
JohnSantaFe
1 Solution
 
AlexFMCommented:
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.
0
 
JohnSantaFeAuthor Commented:
Ah!

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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

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