A thread is a semi-independent programme segment that resides within a programme's execution flashback time.5. Use objects of the CThread class in your program as follows:// CModifiedToolBar.cpp This article focuses on creating and using user-interface threads.
Instructions "New." Click the "Projects" tab and select "MFC AppWizard(exe)." Type a project name under the "Project name" edit box and hit "OK." Select "Single document" and "Document/View architecture support" in the second page of the wizard and press "Finish" and "OK."
2. Create a thread class using the Class Wizard. In the Menu bar, click "View" > "ClassWizard" or simply press Ctrl+W. Choose "Add Class" > "New." Enter "CThread" in the "Name" edit box and choose "CWinThread" for "Base class" in the drop-down menu box. Press "OK" twice. Now the Class Wizard has created Thread "h" and "cpp" files that store the declaration and definition of CThread, respectively.
3. Add a member function to the CThread class for the handling of messages. In the left pane, click the "FileView" tab, expand the "Header Files" directory and double-click "Thread.h" so that it opens in the source editor. Remove "CThread();" under "protected:" by cutting it and paste that line under "public:". Add "void MsgHandler(WPARAM, LPARAM)", the function definition, to the next line. Next, expand the "Source Files" directory and double-click "Thread.cpp" so that it opens in the source editor. Append the function's definition as shown below:
void MyThread::MsgHandler(WPARAM, LPARAM)
{
// message processing code
}
4. Incorporate the CThread class into other MFC projects. If you have derived a class from CToolBar called CModifiedToolBar, you would insert "#include "Thread.h" at the top of the "CModifiedToolBar.cpp" file.
The Microsoft Foundation Organization (MFC) Lib offers the CWinThread organization for moulding principle thread-safe. CWinThread supports Employee threads and user-interface threads. Unlike Employee threads suitable for background processing, user-interface threads appropriateness communication maps and course user-driven messages.
CThread* pThread;
pThread = new CThread();
pThread->CreateThread();
pThread->SetThreadPriority(THREAD_PRIORITY_ABOVE_NORMAL);
pThread->Run();
pThread->SuspendThread();
// etc.