16,472
社区成员
发帖
与我相关
我的任务
分享
//消息泵
{
while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
TranslateMessage(&msg); //处理用户输入字符
DispatchMessage(&msg); //派遣消息
}
}
//消息处理的回调函数
LRESULT CALLBACK MainWndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
TCHAR szText[]= _T("简单的程序!");
switch(message)
{
case WM_PAINT:
{
HDC hdc;
PAINTSTRUCT ps;
hdc=::BeginPaint(hwnd,&ps);
::TextOut(hdc,10,10,szText, _tcslen(szText));
::EndPaint(hwnd,&ps);
return 0;
}
case WM_DESTROY:
::PostQuitMessage(0);
return 0;
}
return ::DefWindowProc(hwnd,message,wParam ,lParam);
}
{
fDone = FALSE;
for(int iLoop = 0; !fDone && iLoop; iLoop++)
{
fDone = DoLengthyOperation(iLoop); //冗长的操作
//从检查是否有键盘消息并取走
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message == WM_KEYDOWN && msg.wParam == 'C')
{
fDone = TRUE; break;
}
}
}
}