win32用法
WM_COMMAND:
視窗選單:
LOWORD(wParam): 選單id
HIWORD(wParam): 0
lParam: 0
如果這個訊息是由子視窗控制項產生,如button產生則:
LOWORD(wParam): 控制項ID
HIWORD(wParam): 通知碼
lParam: 子視窗句柄。
如果這個訊息是由子視窗或者快捷鍵產生則通知碼為1,由選單產生通知碼為0。
通過參數,可以區分這個訊息的來源是來自於控制項,快捷鍵還是選單。
MSDN解釋
WM_COMMAND (上文翻譯)
The WM_COMMAND message is sent when the user selects a command item from a menu, when a control sends a notification message to its parent window, or when an accelerator keystroke is translated.
當用戶從選單選中一個命令項目、當一個控制項傳送通知訊息給去父視窗或者按下一個快捷鍵將傳送 WM_COMMAND 訊息
A window receives this message through its WindowProc function.
視窗通過WindowProc函式收到此訊息。
LRESULT CALLBACK WindowProc(
HWND hwnd // handle to window
UINT uMsg // WM_COMMAND
WPARAM wParam // notification code and identifier
LPARAM lParam // handle to control (HWND)
);
LRESULT CALLBACK WindowProc(
HWND hwnd // 視窗句柄
UINT uMsg // WM_COMMAND
WPARAM wParam // notification code and identifier 訊息
LPARAM lParam // handle to control (HWND) 控制項id
);
Parameters wParam The high-order word specifies the notification code if the message is from a control.如果信息是從控制項傳來,參數wParam高位字指定通知代碼。
If the message is from an accelerator, this value is 1.如果信息是從一個加速器傳來,這個值是1 。
If the message is from a menu, this value is zero.
如果信息是從選單中傳來,這個值是零。 The low-order word specifies the identifier of the menu item, control, or accelerator.低位字的標識符指定的選單項,控制項或加速器。
lParam Handle to the control sending the message if the message is from a control.
lParam如果信息是從控制項傳來,句柄控制傳送信息。
Otherwise, this parameter is NULL.否則,這個參數是無效的。
Return ValuesIf an application processes this message, it should return zero.
返回ValuesIf應用程式這個訊息,它應返回零。
RemarksAccelerator keystrokes that select items from the window menu are translated into WM_SYSCOMMAND messages. RemarksAccelerator擊鍵的選擇項目從視窗選單化為WM_SYSCOMMAND訊息。
If an accelerator keystroke occurs that corresponds to a menu item when the window that owns the menu is minimized, no WM_COMMAND message is sent.如果出現一個加速器按鍵對應的選單項時的視窗,擁有選單最小,沒有WM_COMMAND傳送郵件。 However, if an accelerator keystroke occurs that does not match any of the items in the window's menu or in the window menu, a WM_COMMAND message is sent, even if the window is minimized.但是,如果出現一個加速器按鍵不匹配的任何物品在視窗的選單或視窗選單,一個WM_COMMAND訊息傳送,即使是最小化的視窗。
If an application enables a menu separator, the system sends a WM_COMMAND message with the low-word of the wParam parameter set to zero when the user selects the separator.如果應用程式使選單分離,系統發出了一個WM_COMMAND訊息的低字的wParam參數設定為0時,用戶選擇的分隔設定。
Windows 98, Windows 2000: If a menu is defined with a MENUINFO.dwStyle value of MNS_NOTIFYBYPOS, WM_MENUCOMMAND is sent instead of WM_COMMAND . Windows 98中, Windows 2000中:如果一個選單的定義與MENUINFO.dwStyle價值MNS_NOTIFYBYPOS , WM_MENUCOMMAND傳送不是WM_COMMAND 。
Requirements Windows NT/2000: Requires Windows NT 3.1 or later.要求視窗 NT/2000 :需要Windows NT 3.1或更高版本。
Windows 95/98: Requires Windows 95 or later. 視窗95/98 :需要Windows 95或更新版本。
Header: Declared in Winuser.h; include Windows.h. 標題:中宣布的Winuser.h ;包括Windows.h 。
See AlsoMenus Overview, Menu Messages, HIWORD , LOWORD , MENUINFO , WM_MENUCOMMAND , WM_SYSCOMMAND查看AlsoMenus概況,選單訊息, HIWORD , LOWORD , MENUINFO , WM_MENUCOMMAND , WM_SYSCOMMAND