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
当用户从窗口菜单选择一个命令或当用户选择最大化按钮,最小化按钮,复原按钮或关闭按钮时,一个窗口将会接收该消息
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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现