GetMessage(&msg,0,0,0)的问题?
LRESULT CALLBACK myProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
case WM_CHAR: char chArr[20];
sprintf(chArr,"char is%d",wParam);
MessageBox(hWnd,chArr,"FristPrograme",0);
break;
default:
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShow)
{
//1设计窗口
WNDCLASS wc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor=LoadCursor(0,IDC_CROSS);
wc.hIcon=LoadIcon(0,IDI_ERROR);
wc.hInstance=hInstance;
wc.lpfnWndProc=myProc;
wc.lpszClassName="FristPrograme";
wc.lpszMenuName=0;
wc.style=CS_HREDRAW|CS_VREDRAW;
//2注册窗口
RegisterClass(&wc);
//3制造窗口
HWND hWnd;
hWnd=CreateWindow("FristPrograme","no",WS_OVERLAPPEDWINDOW,
0,0,400,600,0,0,hInstance,0);
//4显示窗口:
ShowWindow(hWnd,SW_SHOWNORMAL);
//5更新窗口:
UpdateWindow(hWnd);
//6消息循环:
MSG msg;//msg为空
while(GetMessage(&msg,0,0,0))
{
//问题: //GetMessage从那里获取消息?我想应该从hWnd(刚才创建的窗口中获取消息)
//所以我想应该写为GetMessage(&msg,hWnd,0,0),然他并不响应!
//可是GetMessage(&msg,0,0,0)从0位置而非hWnd位置获得的消息,居然能相应!
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
GetMessage(&msg,0,0,0)与GetMessage(&msg,hWnd,0,0)区别?为何与我想的不一样呢?