什么消息导致按钮发送 WM_COMMAND 消息
我知道按钮在单击时会向其父级发送 WM_COMMAND 消息,但是它收到什么消息才能发送此消息?我正在覆盖按钮的默认 WndProc,并且按钮不接收 WM_COMMAND 消息,因此我需要知道什么消息导致按钮发送 WM_COMMAND 消息,以便我可以复制该功能。
I know that a Button, when clicked, sends the WM_COMMAND message to it's parent, but what message does it receive that makes it send this message? I am overriding the default WndProc of a button and the button does not receive the WM_COMMAND message, so I need to know what message causes a button to send the WM_COMMAND message so I can replicate that functionality.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我发现它实际上是 WM_LBUTTONDOWN、WM_MOUSELEAVE 和其他一些东西的组合。例如,只有当鼠标在按钮上按下时 WM_COMMAND 才会被触发,并且当 WM_LBUTTONUP 被触发时鼠标仍然在按钮上。至于空格、回车等,我相信它只是处理 VK_ENTER 消息之类的。
I found that it's actually a combination of WM_LBUTTONDOWN, WM_MOUSELEAVE, and a few other things. For example, the WM_COMMAND will only be fired if the mouse was depressed on the button, and is still on the button when WM_LBUTTONUP is fired. As for space, enter, etc, I believe it just handles the VK_ENTER message and stuff.
我似乎记得它是 WM_LBUTTONUP,但使用 Spy 程序可以确定。
I seem to recall it's WM_LBUTTONUP, but use a Spy program to find out for sure.
WM_COMMAND 消息始终由控件父级接收。如果你想以编程方式单击按钮,你可以这样做:
WM_COMMAND 的 LPARAM 保存按钮_句柄。因此,您可以提取有关按钮调用的信息
您必须提前设置此信息,
例如 some_info 可以通过指向按钮包装对象的指针
WM_COMMAND message is always received by controls parent. If you want to click button programmatically you can do this:
LPARAM of WM_COMMAND holds button_handle. So you can extract information about you button calling
You must have been set this information earlier like this
for example some_info can by pointer to button wrapper object
无法覆盖
WM_COMMAND
消息,因为WM_LBUTTONDOWN
消息会转换为WM_COMMAND
消息并将其发送到父控件。这是在后台完成的机制。您询问了空格和输入键。这可以通过虚拟键代码控制,例如
vk_enter
、vk_tab
...等,It is not possible to override
WM_COMMAND
message becauseWM_LBUTTONDOWN
message is converted asWM_COMMAND
message and send it to parent control. This is the mechanism that is done in the background.You asked about space and enter key.This can be controlled by virtual key codes like
vk_enter
,vk_tab
...etc.,