alberthyc

I got MFC dialog with a worker thread. this worker thread this to get the position of the sliders and output them.

obviously, my worker thread can't touch the sliders either directly or implictly. So i have to send notification message to somewhere which i'm not sure, to let some function outside the worker thread do the job.

i'm not sure where to implement the message,

for example:

// CMultithreadingTestApp

BEGIN_MESSAGE_MAP(CMultithreadingTestApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp:SurprisenHelp)
ON_MESSAGE (WM_USER_GET_DATA, OnGetData)//<-Complier ERROR here
ON_MESSAGE (WM_USER_THREAD_ABORTED, OnThreadAborted)//<-Complier ERROR here

END_MESSAGE_MAP()

if i implement this, i got error

error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CMultithreadingTestApp::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' None of the functions with this name in scope match the target type

if i implement the message between

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)

....
END_MESSAGE_MAP()

i'm afraid some deadlock will happen.

read this section "Worker threads and the GUI II: Don't touch the GUI" of this article: http://www.flounder.com/workerthreads.htm



Re: Visual C++ Language How to implement user defined message in a Dialog box with a worker thread?

rtpninja

You've got the right idea. Rather than touching the sliders from the worker thread directly, you want to send a message to the UI thread and have it update them. So you register a couple of window messages - again, good.

The only problem I see is that you're attempting to handle these messages in your application class. Those handlers want to hook up to a CWnd-derived class - a window, in other words. Which makes sense, because it's a window message you're sending.

So add a handler for those messages in your CDialog's message map and you should be good to go.

If I'm understanding you correctly.

Good luck!





Re: Visual C++ Language How to implement user defined message in a Dialog box with a worker thread?

alberthyc

hi, thx for the reply, i got the problem fixed.

I should implement message in the CDialog message map.