while True do
begin
if not PeekMessage(msg,0,0,0,PM_REMOVE) then
begin
case MsgWaitForMultipleObjects(1,hCloseEvent,False,INFINITE,QS_ALLINPUT) of
WAIT_OBJECT_0: Break;//hCloseEvent事件已经有效,故结束
WAIT_OBJECT_0+1:Continue;//消息队列中有消息存在
else Break;//其它情况,WM_FAILED或WAIT_ABANDONED_0,表明已经出错,故结束
end;
end else
begin
if WaitForSingleObject(hCloseEvent,0)<>WAIT_TIMEOUT then Break;
case msg.message of
WM_TEST:
begin
//...接到主线程发过来的命令,作相应处理
//...处理完之后,也可以用消息通知主线程
end;
end;
end;
end;
finally
//...作善后处理
end;