俺们初学VC,呵呵,被WPARAM,LPARAM 弄晕了,GGJJ们帮俺看一下下面这段程序:
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,
WPARAM wParam,LPARAM lParam)
{
int wmId,wmEvent;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch(wmId)
{
case IDM_ABOUT:
DialogBox(_hInst,
"AboutBox",
hWnd,
(DLGPROC)About
);
break;
case IDM_EXIT:
DestroyWindow (hWnd);
break;
default:
return(DefWindowProc(hWnd,message,wParam,lParam));
}
break;
case WM_DESTROY: // 窗口已经被摧毁,程序即将结束。
PostQuitMessage(0);
break;
default:
return (DefWindowProc(hWnd,message,wParam,lParam));
}
return (0);
}
程序就是侯俊杰《深入浅出》里面的Generic程序的一段,照搬下来运行得很好,窗口能出来,对话框也没问题。
但是当我把红色部分的wParam改为lParam以后,窗口还能出来,但对话框却没了,这是怎么回事?当我点击了help栏下面的“About...”以后这两个参数到底都发生了什么变化?
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,
WPARAM wParam,LPARAM lParam)
{
int wmId,wmEvent;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch(wmId)
{
case IDM_ABOUT:
DialogBox(_hInst,
"AboutBox",
hWnd,
(DLGPROC)About
);
break;
case IDM_EXIT:
DestroyWindow (hWnd);
break;
default:
return(DefWindowProc(hWnd,message,wParam,lParam));
}
break;
case WM_DESTROY: // 窗口已经被摧毁,程序即将结束。
PostQuitMessage(0);
break;
default:
return (DefWindowProc(hWnd,message,wParam,lParam));
}
return (0);
}
程序就是侯俊杰《深入浅出》里面的Generic程序的一段,照搬下来运行得很好,窗口能出来,对话框也没问题。
但是当我把红色部分的wParam改为lParam以后,窗口还能出来,但对话框却没了,这是怎么回事?当我点击了help栏下面的“About...”以后这两个参数到底都发生了什么变化?
wNotifyCode = HIWORD(wParam); // notification code
wID = LOWORD(wParam); // item, control, or accelerator identifier
hwndCtl = (HWND) lParam; // handle of control
Parameters
wNotifyCode
Value of the high-order word of wParam. Specifies the notification code if the message is from a control. If the message is from an accelerator, this parameter is 1. If the message is from a menu, this parameter is 0.
wID
Value of the low-order word of wParam. Specifies the identifier of the menu item, control, or accelerator.
hwndCtl
Value of lParam. Handle to the control sending the message if the message is from a control. Otherwise, this parameter is NULL.