Win32 中的GetMessage的问题?
#include <windows.h>#include <string>
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam,// first message parameter
LPARAM lParam // second message parameter
);
LRESULT CALLBACK WndProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam,// first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance,// handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
WNDCLASS wndClass;
wndClass.cbClsExtra=0;
wndClass.cbWndExtra=0;
wndClass.hbrBackground=(HBRUSH)::GetStockObject(WHITE_BRUSH);
wndClass.hCursor=\LoadCursor(hInstance,IDC_ARROW);
wndClass.hIcon=\LoadIcon(hInstance,IDI_APPLICATION);
wndClass.hInstance=hInstance;
wndClass.lpszClassName="sqzxcv";
wndClass.lpfnWndProc=WndProc;
wndClass.lpszMenuName=NULL;
wndClass.style=CS_VREDRAW|CS_HREDRAW;
::RegisterClass(&wndClass);
HWND hwnd=CreateWindow(
TEXT("sqzxcv"), // window class name
TEXT("ľÌÇÌì¿Õ"),// window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL); // creation parameters
if (hwnd==NULL)
{
return 0;
}
::ShowWindow(hwnd,SW_NORMAL);
::UpdateWindow(hwnd);
MSG msg;
while (::GetMessage(&msg,hwnd,0,0))//*********************@1
{/*::GetMessage(&msg,NULL,0,0)*///**********************@2
::TranslateMessage(&msg);
\DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
//HDC hdc;
//PAINTSTRUCTps;
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
} // WndProc
为什么当用@1时,如果程序退出,应用程序的进程并不会结束,而且这个应用程序的进程狅占CPU,是为什么?
要是用@2 就不会出现这个问题。。。。
[ 本帖最后由 sqzxcv 于 2009-12-3 19:27 编辑 ]
页:
[1]