windows_programming_notes.nbk: Home | Index | Next Page: WM_SYSDEADCHAR | Previous Page: WM_SYSCOLORCHANGE


 WM_SYSCOMMAND

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.

A window receives this message through its WindowProc function.

    LRESULT CALLBACK WindowProc(
      HWND hwnd,       // handle to window
      UINT uMsg,       // WM_SYSCOMMAND
      WPARAM wParam,   // system command type
      LPARAM lParam    // horizontal and vertical position
    );

Parameters

1 - the display is going to low power 2 - the display is being shut off

SC_MOUSEMENU Retrieves the window menu as a result of a mouse click. SC_MOVE Moves the window. SC_NEXTWINDOW Moves to the next window. SC_PREVWINDOW Moves to the previous window. SC_RESTORE Restores the window to its normal position and size. SC_SCREENSAVE Executes the screen saver application specified in the [boot] section of the System.ini file. SC_SIZE Sizes the window. SC_TASKLIST Activates the Start menu. SC_VSCROLL Scrolls vertically.

Return Values

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

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

  Windows NT/2000 or later: Requires Windows NT 3.1 or later.
  Windows 95/98/Me: Requires Windows 95 or later.
  Header: Declared in Winuser.h; include Windows.h.

windows_programming_notes.nbk: Home | Index | Next Page: WM_SYSDEADCHAR | Previous Page: WM_SYSCOLORCHANGE


Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time