Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

How to know which thread executes a certain windows message Q

I have created an UI thread and another class (say X) inherriting CFrameWnd, now i miss equating my thread's m_pMainWnd variable to my newly created instance of X. I went forward with posting messages to X's Q and it is working. The query is in the context of which thread, the main application one or my UI thread, are these posted messages getting executed.
0
shell_gem
Asked:
shell_gem
1 Solution
 
KurtVonCommented:
Well, it is easy to see which in the debugger.  Put a breakpoint in the message handler and then go to the "Threads" window when it breaks.  In Visual Studio 6.0 go to Debug|Thread... in the menu.  In Visual Studio .Net there is a "Threads" window in the same tab section as the call stack window.

Either way, you can see a list of all the threads executing and figure out which one is stopped in your function.

For the record, unless you are leaving some information out, the main application thread should be handling the messages.
0
 
SteHCommented:
Normally you need to post the messages to your thread to be executed by that thread. And a UI thread needs a class to be used for excution:

m_pYourThread = (CYourThread*) AfxBeginThread (RUNTIME_CLASS(CYourThread),
        THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED, NULL);
is a way to start this thread. To post messages to it you use either the pointer to that thread:

m_pYourThread->PostThreadMessage (message, wParam, lParam);

or use the thread ID:

::PostThreadMessage (idThread, message, wParam, lParam)

Otherwise messages are posted to the main thread but might be handled by different windows.
0
 
PriyeshCommented:
You can try a trace before your query statements.

like TRACE("Thread ID = %d, executing query xxx "\n", GetCurrentThreadId()) ;

so you know which thread does it.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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