![]() |
|
#1
|
|||
|
|||
Sending message to GUI thread that ISNT the main threadI am trying to send a user defined message to a secondary thread in my dialog based MFC application. My secondary thread is a derivative of the CWinThread class and I am launching it using:
CPP / C++ / C Code:
From my main GUI thread, I would like to send a message to this secondary thread, I am using: CPP / C++ / C Code:
My problem however is that when I do this, I get an error code 1400: invalid window handle. How would I go about getting a valid handle to my thread class? Is there an easier / better way to accomplish this? The ultimate reason I am doing this is to send a CString to my second thread when a button is clicked in my main GUI thread. Thanks in advance for the help, I am very new to MFC / VC++ -Mike Visconti Last edited by LuciWiz : 19-Apr-2005 at 23:23.
Reason: Please insert your C++ code between [c++] & [/c++] tags
|
|
#2
|
|||
|
|||
|
A (despite its name) "user interface thread" does not have a window associated with it by default. If you want to use any function that requires a window handle (HWND) you need to create a window (can be invisible) first.
I much prefer to use PostThreadMessage, it takes a thread id as destination. The m_nThreadID member of the CWinThread class serves well for this purpose. Use ON_THREAD_MESSAGE macro in your message map to catch the messages. e.g CPP / C++ / C Code:
|
Recent GIDBlog
Toyota - 2008 September Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Another problem dealing with main() and driver function | tommy69 | C Programming Language | 4 | 20-Mar-2004 19:46 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The