Solved

<=== >  Message Pump  <===>

Posted on 1998-07-02
4
666 Views
Last Modified: 2013-11-19
if a worker thread is derived from CWinThread using AfxBeginThread why does it not have a message pump ???
0
Comment
Question by:pcj0961
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 50 total points
ID: 1318664
There are tow kind of of thread, UI thread and worker thread. UI thread contains message pump and in MFC usually derived from CWinThread. Worker thread is usually thread function so when this function returns worker thread terminates. Thre are two overloaded version of AfxBeginThread. When you create UI thread you cpesify pointer to CWinThread class. This class has Run virtual function that contains message pump. The second version of AfxBeinThread is passed pointer to worker thread entry function.
0
 
LVL 1

Author Comment

by:pcj0961
ID: 1318665
I have created a worker thread using AfxBeginThread
that has a for(;;){} loop that never returns (it runs continuosly looking for messages passed to it). Is it better
to do this type of application (thread) with a UI thread and use the Run(){} loop of the CWinThread object to do my processing.
0
 
LVL 7

Expert Comment

by:galkin
ID: 1318666
Worker thread doesn't have any windows so it is impossible to send message to it. Usually worker thread does some data processing and notifies main UI thread using messages. If you still want your worker thread to have a window, create hidden window inside CWinThread::InitInstance and assign it's pointer to m_pMainWnd. then you can send messages to this hidden window.
0
 
LVL 4

Expert Comment

by:piano_boxer
ID: 1318667
Any thread can have a message pump! But if the thread do not create any windows or do not need to receive messages posted using PostThreadMessage() there is no reason to do a message pump.

Remember: Windows are owned by the thread that created them.


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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
A short film showing how OnPage and Connectwise integration works.

914 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

15 Experts available now in Live!

Get 1:1 Help Now