【蹩脚读MSDN】之WM_COMMAND

本文详细解析了WM_COMMAND消息的工作原理及处理方式。当用户选择菜单项、控件通知父窗口或快捷键被触发时,系统将发送WM_COMMAND消息。文章还介绍了如何通过回调函数处理这些消息,并解释了关键参数wParam和lParam的作用。

蹩脚读MSDNWM_COMMAND

The WM_COMMAND message is sent when the user selects a command item from a menu, when a control sends a notification message to its parent window, or when an accelerator keystroke is translated.

当用户从菜单选中一个命令选项或者控件向父窗口发送消息或者接受到一个快捷键信息时会接受到该消息

A window receives this message through its WindowProc function.

窗口的回调函数接受到WM_COMMAND消息

LRESULT CALLBACK WindowProc(

  HWND hwnd,       // handle to window    窗口句柄

  WM_COMMAND,      // the message to send   

  WPARAM wParam,   // notification code and identifier   

  LPARAM lParam    // handle to control (HWND)

);

Parameters

wParam

The high-order word specifies the notification code if the message is from a control. If the message is from an accelerator, this value is 1. If the message is from a menu, this value is zero.

 

如果消息来自一个控件则wparam的高位返回通知码

如果该消息来自快捷键 则wparam的高位返回返回1

如果该消息来自命令菜单 则wparam的高位返回返回0

The low-order word specifies the identifier of the menu item, control, or accelerator.

无论消息是来自控件 快捷键 还是命令菜单 wparam的低位都表示该

控件(快捷键.命令菜单)ID

lParam

Handle to the control sending the message if the message is from a control. Otherwise, this parameter is NULL.

如果消息来自控件则lparam返回该消息的句柄  否则返回NULL

Return Values

If an application processes this message, it should return zero.

如果应用程序处理此消息时,它应返回零。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值