WM_SYSCOMMAND 函数

WM_SYSCOMMAND Notification

当用户从窗口菜单选择一个命令或当用户选择最大化按钮,最小化按钮,复原按钮或关闭按钮时,一个窗口将会接收该消息

Syntax

WM_SYSCOMMAND

WPARAM wParam
LPARAM lParam;


参数

wParam

指定系统命令的类型。该参数可以是下列值之一:

SC_CLOSE

关闭窗口

SC_CONTEXTHELP

将光标改为一个问题标识样式。如果用户之后点击了对话框中的一个控件,该控件会收到一个WM_HELP消息。

SC_DEFAULT

当用户双击窗口菜单时,选择默认的条目。

SC_HOTKEY

以应用程序指定的热键激活窗口。lParam参数标识了所要激活的窗口。

SC_HSCROLL

水平滚动。

SC_KEYMENU

键盘的敲击返回窗口菜单。

SC_MAXIMIZE

最大化窗口

SC_MINIMIZE

最小化窗口

SC_MONITORPOWER

设置显示状态。该命令支持具有节电特性的设备,如电池供电的个人电脑。

lParam参数可以具有下列值:

-1 - 显示设备打开

1 - 显示设备将要进入节电模式。

2 - 显示设备将要被关闭

SC_MOUSEMENU

鼠标单击返回窗口菜单。

SC_MOVE

移动窗口

SC_NEXTWINDOW

移到下一个窗口

SC_PREVWINDOW

移到前一个窗口

SC_RESTORE

将窗口复原到原始的位置和大小。

SC_SCREENSAVE

执行System.ini文件里[boot]部分指定的屏幕保护程序。

SC_SIZE

改变窗口大小。

SC_TASKLIST

激活【开始】菜单。

SC_VSCROLL

垂直滚动。

lParam

如果一个窗口命令被鼠标选中,低位字指定光标的水平位置。否则该参数不被使用。
如果一个窗口命令被鼠标选中,高位字指定光标的垂直位置。如果使用系统加速键选择的命令,则该参数为-1,如果使用助记符的话,则该参数为0.

返回值

如果成功处理该消息,则返回值为0.

备注

获得屏幕坐标系下的位置坐标,可以使用下面的代码:

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.

Microsoft Windows Vista and later: 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'.

消息要求

Minimum DLL Version None
Header Declared in Winuser.h, include Windows.h
Minimum operating systems Windows 95, Windows NT 3.1

原文地址:https://www.cnblogs.com/BeyondTechnology/p/1995930.html