//...
}
BOOLCTestThreadApp::WaitMyEvent(HANDLEhObject)
{
while(TRUE)
{
MSGmsg;
while(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
//Ifit'saquitmessage,we'reoutofhere.
if(msg.message==WM_QUIT)
returnFALSE;
//Otherwise,dispatchthemessage.
TranslateMessage(&msg);
DispatchMessage(&msg);
}//EndofPeekMessagewhileloop.
//Waitforanymessagesentorpostedtothisqueue
//orforoneofthepassedhandlesbesettosignaled.
DWORDresult=MsgWaitForMultipleObjects(1,&m_hEvent,
FALSE,INFINITE,QS_ALLINPUT);
if(result==WAIT_OECT_0)
returnTRUE;
}
}
//用户界面线程为:
#defineWM_TEST(WM_USER+1)
classCMyUIThread:publicCWinThread
{
DECLARE_DYNCREATE(CMyUIThread)
protected:
CMyUIThread();//protectedconstructorusedbydynamiccreation
//Operations
public:
//Overrides
//ClassWizardgeneratedvirtualfunctionoverrides
//{{AFX_VIRTUAL(CMyUIThread)
public:
virtualBOOLInitInstance();
virtualintExitInstance();
//}}AFX_VIRTUAL
//Implementation
protected:
virtual~CMyUIThread();
LRESULTOnTest(WPARAMwParam,LPARAMlParam);
DECLARE_MESSAGE_MAP()
};
//MyUIThread.cpp:implementationfile
#include"stdafx.h"
#include"TestThread.h"
#include"MyUIThread.h"
IMPLEMENT_DYNCREATE(CMyUIThread,CWinThread)
CMyUIThread::CMyUIThread()
{}
CMyUIThread::~CMyUIThread()
{}
BOOLCMyUIThread::InitInstance()
{
//TODO:performandper-threadinitializationhere
returnTRUE;
}
intCMyUIThread::ExitInstance()
{
//TODO:performanyper-threadcleanuphere
returnCWinThread::ExitInstance();
}
BEGIN_MESSAGE_MAP(CMyUIThread,CWinThread)
//{{AFX_MSG_MAP(CMyUIThread)
//NOTE-theClassWizardwilladdandremovemappingmacroshere.
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-23463-6.html
更是凭着优异的航速和猛烈的火力