WM_SYSCOMMAND message (Windows)

Switch View :
ScriptFree
WM_SYSCOMMAND message

Applies to: desktop apps only

A window receives this message when the user chooses a command from the Window menu (formerly known as the system or control menu) or when the user chooses the maximize button, minimize button, restore button, or close button.

#define WM_SYSCOMMAND                   0x0112

Parameters

wParam

The type of system command requested. This parameter can be one of the following values.

ValueMeaning
SC_CLOSE
0xF060

Closes the window.

SC_CONTEXTHELP
0xF180

Changes the cursor to a question mark with a pointer. If the user then clicks a control in the dialog box, the control receives a WM_HELP message.

SC_DEFAULT
0xF160

Selects the default item; the user double-clicked the window menu.

SC_HOTKEY
0xF150

Activates the window associated with the application-specified hot key. The lParam parameter identifies the window to activate.

SC_HSCROLL
0xF080

Scrolls horizontally.

SCF_ISSECURE
0x00000001

Indicates whether the screen saver is secure.

SC_KEYMENU
0xF100

Retrieves the window menu as a result of a keystroke. For more information, see the Remarks section.

SC_MAXIMIZE
0xF030

Maximizes the window.

SC_MINIMIZE
0xF020

Minimizes the window.

SC_MONITORPOWER
0xF170

Sets the state of the display. This command supports devices that have power-saving features, such as a battery-powered personal computer.

The lParam parameter can have the following values:

  • -1 (the display is powering on)
  • 1 (the display is going to low power)
  • 2 (the display is being shut off)
SC_MOUSEMENU
0xF090

Retrieves the window menu as a result of a mouse click.

SC_MOVE
0xF010

Moves the window.

SC_NEXTWINDOW
0xF040

Moves to the next window.

SC_PREVWINDOW
0xF050

Moves to the previous window.

SC_RESTORE
0xF120

Restores the window to its normal position and size.

SC_SCREENSAVE
0xF140

Executes the screen saver application specified in the [boot] section of the System.ini file.

SC_SIZE
0xF000

Sizes the window.

SC_TASKLIST
0xF130

Activates the Start menu.

SC_VSCROLL
0xF070

Scrolls vertically.

 

lParam

The low-order word specifies the horizontal position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. Otherwise, this parameter is not used.

The high-order word specifies the vertical position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. This parameter is –1 if the command is chosen using a system accelerator, or zero if using a mnemonic.

Return value

An application should return zero if it processes this message.

Remarks

To obtain the position coordinates in screen coordinates, use the following code:



xPos = GET_X_LPARAM(lParam);    // horizontal position 
yPos = GET_Y_LPARAM(lParam);    // vertical position


The DefWindowProc function carries out the window menu request for the predefined actions specified in the previous table.

In WM_SYSCOMMAND messages, the four low-order bits of the wParam parameter are used internally by the system. To obtain the correct result when testing the value of wParam, an application must combine the value 0xFFF0 with the wParam value by using the bitwise AND operator.

The menu items in a window menu can be modified by using the GetSystemMenu, AppendMenu, InsertMenu, ModifyMenu, InsertMenuItem, and SetMenuItemInfo functions. Applications that modify the window menu must process WM_SYSCOMMAND messages.

An application can carry out any system command at any time by passing a WM_SYSCOMMAND message to DefWindowProc. Any WM_SYSCOMMAND messages not handled by the application must be passed to DefWindowProc. Any command values added by an application must be processed by the application and cannot be passed to DefWindowProc.

If password protection is enabled by policy, the screen saver is started regardless of what an application does with the SC_SCREENSAVE notification—even if fails to pass it to DefWindowProc.

Accelerator keys that are defined to choose items from the window menu are translated into WM_SYSCOMMAND messages; all other accelerator keystrokes are translated into WM_COMMAND messages.

If the wParam is SC_KEYMENU, lParam contains the character code of the key that is used with the ALT key to display the popup menu. For example, pressing ALT+F to display the File popup will cause a WM_SYSCOMMAND with wParam equal to SC_KEYMENU and lParam equal to 'f'.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

See also

Reference
AppendMenu
DefWindowProc
GET_X_LPARAM
GET_Y_LPARAM
GetSystemMenu
InsertMenu
ModifyMenu
WM_COMMAND
Conceptual
Keyboard Accelerators

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Community Content

btarb24
omitted command
SC_DRAGMOVE = 0xf012 Happens when you drag a window. I specifically get it when i send WM_NCLBUTTONDOWN with HT_CAPTION. It also seems to be followed by a WM_ACTIVATE.

Cube 8
AND 0xFFF0 is important
I tried to capture the case when the user clicks on the window icon but I forgot to "normalize" wParam and I got a value of 0xF093, on XP x64. So it is indeed necessary to AND with the value 0xFFF0.

Fistynuts1
SC_MONITORPOWER doesn't work
The SC_MONITORPOWER command no longer seems to work on Windows 7. This isn't mentioned here on MSDN - are there any alternatives that can be used to force all connected monitors into power-saving mode, given that the SPI_SETPOWEROFFACTIVE and SPI_SETPOWEROFFTIMEOUT options to SystemParametersInfo have also stopped working?

dfsdxfSDFSDFS
Values in C#
public enum SystemCommands
{ 
    SC_SIZE = 0xF000,
    SC_MOVE = 0xF010,
    SC_MINIMIZE = 0xF020, 
    ///<summary>
/// Sent when form maximizes
///</summary>
SC_MAXIMIZE = 0xF030,
    ///<summary>
/// Sent when form maximizes because of doubcle click on caption
/// JTE: Don't use this constant. As per the documentation, you
/// must mask off the last 4 bits of wParam by AND'ing it
/// with 0xFFF0. You can't assume the last 4 bits.
///</summary>
SC_MAXIMIZE2 = 0xF032,
SC_NEXTWINDOW = 0xF040,
SC_PREVWINDOW = 0xF050,
///<summary>
/// Closes the form
///</summary>
SC_CLOSE = 0xF060,
SC_VSCROLL = 0xF070,
SC_HSCROLL = 0xF080,
SC_MOUSEMENU = 0xF090,
SC_KEYMENU = 0xF100,
SC_ARRANGE = 0xF110,

///<summary>
/// Sent when form is maximized from the taskbar
///</summary>
SC_RESTORE = 0xF120,
///<summary>
/// Sent when form maximizes because of doubcle click on caption
/// JTE: Don't use this constant. As per the documentation, you
/// must mask off the last 4 bits of wParam by AND'ing it
/// with 0xFFF0. You can't assume the last 4 bits.
///</summary>
SC_RESTORE2 = 0xF122,
SC_TASKLIST = 0xF130,
SC_SCREENSAVE = 0xF140,
SC_HOTKEY = 0xF150,
SC_DEFAULT = 0xF160,
SC_MONITORPOWER = 0xF170,
SC_CONTEXTHELP = 0xF180,
SC_SEPARATOR = 0xF00F
}

Đonny
Value
WM_SYSCOMMAND = &H112

Public Enum WM_SYSCOMMAND As Integer
SC_CLOSE = &HF060I
SC_CONTEXTHELP = &HF180
SC_DEFAULT = &HF160
SC_HOTKEY = &HF150
SC_HSCROLL = &HF080
SC_KEYMENU = &HF100
SC_MAXIMIZE = &HF030I
SC_MINIMIZE = &HF020I
SC_MONITORPOWER = &HF170
SC_MOUSEMENU = &HF090
SC_MOVE = &HF010
SC_NEXTWINDOW = &HF040
SC_PREVWINDOW = &HF050
SC_RESTORE = &HF120
SC_SCREENSAVE = &HF140
SC_SIZE = &HF000
SC_TASKLIST = &HF130
SC_VSCROLL = &HF070
End Enum