Solved

How to know which thread executes a certain windows message Q

Posted on 2003-11-12
3
197 Views
Last Modified: 2013-11-20
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
Comment
Question by:shell_gem
3 Comments
 
LVL 11

Accepted Solution

by:
KurtVon earned 100 total points
ID: 9731740
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
 
LVL 13

Expert Comment

by:SteH
ID: 9731991
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
 
LVL 9

Expert Comment

by:Priyesh
ID: 9737405
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa‚Ķ
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question