Download all the Zip files, recommended.
ThreadMSG dialog looks some what like this:

The Thread starting with AfxBeginThread dialog looks like this:

Description
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
{DECLARE_DYNCREATE(Thread)
public:....
afx_msg void OnRun(WPARAM wParam,LPARAM lParam);
DECLARE_MESSAGE_MAP()
};
IMPLEMENT_DYNCREATE(PlaySound1, CWinThread)
BEGIN_MESSAGE_MAP(PlaySound1, CWinThread)
ON_THREAD_MESSAGE(WM_ON_RUN,OnRun)
END_MESSAGE_MAP()
void OnRun(WPARAM wp,LPARAM lp)
{
.....
.....
}
BOOL CThreadMSGDlg::OnInitDialog()
{Thread *pThread;
pThread=new Thread;
pThread->CreateThread();
play->PostThreadMessage(WM_ON_RUN,0,0);
...
...
return TRUE;
}
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 threadID.
- 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.
Use 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:sammyitm@hotmail.com?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.