Solved

How to know which thread executes a certain windows message Q

Posted on 2003-11-12
3
195 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sumNumber challenge 16 111
bigDiff challenge 17 84
My project did see openJDK that I installed. What could be the problem 7 124
noX challenge 17 92
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

864 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now