0

I have a dialog where the user is able to enter information and then press the Go button. When they press this button I disable the form elements (buttons etc) and create a worker thread using AfxBeginThread( ... ). Once the worker thread has completed I want it to send a message to the UI thread so as to re-enable the form. I am using ::PostMessage( ... ) to send the message, but I can't find how to intercept these messages.

i've searched online (Link #1, Link #2, Link #3) but I can't find an understandable example of the code to implement my own message listener. In the header I can see some crazy define statements (started with DECLARE_MESSAGE_MAP()) which looks like it may have something to do with it, but I can't figure it out.

Any help is much appreciated. Thanks.

Community
  • 1
  • 1
Luke
  • 560
  • 6
  • 26
  • 1
    Make sure you use a message from the [`WM_APP`](http://msdn.microsoft.com/en-us/library/windows/desktop/ms644930(v=vs.85).aspx) range. – Mark Ransom Aug 22 '13 at 18:00

1 Answers1

3

The message map is a table. For each message you are interested in it contains the message and a function pointer to the message handler function. To add a custom message to the map you add an ON_MESSAGE entry to the table. A tutorial example of doing this from a worker thread is here:

http://vcfaq.mvps.org/mfc/12.htm

ScottMcP-MVP
  • 10,337
  • 2
  • 15
  • 15
  • I found http://msdn.microsoft.com/en-us/library/k35k2bfs.aspx and the article you linked to has an error a believe. It uses `UINT` and `LONG` where it should use `WPARAM` and `LPARAM`. The MSDN article I linked to worked. Thanks for the help though. – Luke Aug 23 '13 at 09:16