俺们初学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...”以后这两个参数到底都发生了什么变化?

解决方案 »

  1.   

    WM_COMMAND 
    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. 
      

  2.   

    对于不同的消息,WPARAM与LPARAM的作用是不同的,你上面处理的WM_COMMAND消息,LPARAM表示的是发消息子控件的窗口句柄也就是HWND,WPARAM的高位是通知码,低位是控件ID
      

  3.   

    Up ls的,具体的代表什么要参看MSDN了
      

  4.   

    这个wParam和lParam是跟具体消息有关的,另外wParam和 lParam不能互换你自己自定义消息时,PostMessage(WM_***, x, y),处理消息时,显然x和y不一样