?
Solved

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

Posted on 1998-07-02
4
Medium Priority
?
681 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 100 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month15 days, 21 hours left to enroll

850 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