Solved

How to know which thread executes a certain windows message Q

Posted on 2003-11-12
3
194 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 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

8 Experts available now in Live!

Get 1:1 Help Now