Download all the Zip files, recommended.
ThreadMSG dialog looks some what like this:
The Thread starting with
AfxBeginThread dialog looks like this:
This little software does noting but start a Thread, and the title bar blinks to show that it is running. Although a number of threads can be started, in this program that feature has not been stressed. It only handles MSG messages that are send to it or posted to it. One way of doing it can be deriving a class from
CWinThread using its normal message maps.
class Thread:public CWinThread
afx_msg void OnRun(WPARAM wParam,LPARAM lParam);
void OnRun(WPARAM wp,LPARAM lp)
But here, I am using a trick. No need to derive a class from
CWinThread. But first download the source code, and then you will find the following methods being implemented there:
- First method: The Thread is being started using API function
CreateThread(....). This also takes a parameter as a pointer to its
threadID and returns the thread ID. This ID is referred to while posting messages by
PostThreadMessage(...) in a very similar way.
_beginthread(....) function can be used which also gives us the
- Second method: The Thread can also be started using (Preferred in MFC based programs)
AfxBeginThread(ThreadProc,lpvoidParam). What it returns is the pointer to a
CWinThread object. And there is a public member variable in it:
m_nThreadID. So, it also gets initialized by this function. This can be used to post messages to it.
PeekMessage to see if there is any message, because this function returns if there is no message, while
GetMessage waits infinitely until there is no message. This can lead to blocking of the thread. So take care.
If you have any problems or any queries, feel free to write to me at mailto:firstname.lastname@example.org?subject=query about project.
I am 20 yrs old and a student at Institute of Technology and Management College (www.itmindia.edu) in India.I am doing electronics and communication engineering. My main interests are in computer programming (DirectX,voice,internet srevers and client. Apart from these I have also interest in electronics. I recently made a project using microcontroller(PSoC) and data transfer mechanism using transistor and also in DTMF. I would like to make projects that use electronics as well as computer programming.