17 out of 43 rated this helpful - Rate this topic

WM_COMMAND message

Applies to: desktop apps only

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.

#define WM_COMMAND                      0x0111

Parameters

wParam

For a description of this parameter, see Remarks.

lParam

For a description of this parameter, see Remarks.

Return value

If an application processes this message, it should return zero.

Remarks

Use of the wParam and lParam parameters are summarized here.

Message SourcewParam (high word)wParam (low word)lParam
Menu0Menu identifier (IDM_*)0
Accelerator1Accelerator identifier (IDM_*)0
ControlControl-defined notification codeControl identifierHandle to the control window

 

Menus

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.

If a menu is defined with a MENUINFO.dwStyle value of MNS_NOTIFYBYPOS, WM_MENUCOMMAND is sent instead of WM_COMMAND.

Accelerators

Accelerator keystrokes that select items from the window menu are translated into WM_SYSCOMMAND messages.

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

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

See also

Reference
HIWORD
LOWORD
Conceptual
Menus

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Simulating a button click (ON_BN_CLICKED).
In this case m_hWnd is the window handle, and I'm simulating the click of a button IDC_OK


//
// When orders are scanned, we simulate the OK button click
// so that the user can automatically move to the next screen
//
WPARAM wParam = MAKEWPARAM( IDC_OK, BN_CLICKED );
LPARAM lParam = (LPARAM)GetDlgItem(IDC_OK);
BOOL bval = ::PostMessage(m_hWnd, WM_COMMAND, wParam, lParam);

==
Took a bit of poking around to figure out that m_hWnd worked but not NULL.

--Ajay
Value
WM_COMMAND = &H111 ; REM this is BASIC style


WM_COMMAND = 0x111 // this is for those writing in C/C++
Restating the obvious about the WM_COMMAND message
Raymond Chen wrote an excellent article that states more clearly what is written in the documentation about the WM_COMMAND message.
http://blogs.msdn.com/oldnewthing/archive/2006/03/02/542115.aspx