Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer


The framework calls this member function when the user generates an application command event. Such an event occurs when the user clicks an application command button or types an application command key.

afx_msg void OnAppCommand(
    CWnd* pWnd,
    UINT nCmd,
    UINT nDevice,
    UINT nKey



[in] pWnd

Pointer to a CWnd object that represents the window where the user clicked the comman button or pressed the command key. This window can be a child window of the window receiving the message.

[in] nCmd

Indicates the application command. For a list of possible values, see the commands under the cmd section of the lParam parameter of WM_APPCOMMAND.

[in] nDevice

The input device that generated the input event. For a list of possible values, see the devices under the uDevice section of the lParam parameter of WM_APPCOMMAND.

[in] nKey

Indicates any virtual keys that are down, such as the CTRL key or the left mouse button. For a list of possible values, see the keys under the dwKeys section of the lParam parameter of WM_APPCOMMAND. For more information, see the "Message Parameters" subheading in About Mouse Input.

This method receives the WM_APPCOMMAND notification, which is described in the Windows SDK.


This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function.

Header: afxwin.h

This method is supported in Windows Vista and later.

Additional requirements for this method are described in Build Requirements for Windows Vista Common Controls.

© 2015 Microsoft