Win32 API:从控件WindowProc中检测WM_COMMAND [英] Win32 API: Detect WM_COMMAND from control WindowProc

查看:115
本文介绍了Win32 API:从控件WindowProc中检测WM_COMMAND的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。

在控件的窗口程序中是否有办法检测按钮或更改编辑控件内容等内容?

在我看过的所有例子中,从父母那里检测出类似的东西。


我能想到的一个显而易见的方法是定义一种新类型的消息,例如: / p>

 #define WM_COMMAND_SENT(WM_USER + 0x0001)



并从中调用父母的窗口程序:

 // ... 
case WM_COMMAND:
SendMessage((HWND) lParam,WM_COMMAND_SENT,wParam,0);
休息;
//...



这样,在孩子的窗口过程中我只能检测到WM_COMMAND_SENT消息知道从wParam发送了什么通知。

然而,这似乎不是一个非常干净的解决方案。

有没有人知道更好的方法?

解决方案

如果切换到MFC,那么您的问题也会得到简化。它支持"消息反射":
https://msdn.microsoft.com/en-us /library/yef4xasc.aspx


Hi.
Is there any way to detect things like the push of a button or changes to the content of an edit control, within the control's window procedure?
In all the exapmples I have seen, things like those are detected from the parent.

One obvious way I can think of would be defining a new type of message, like:

#define WM_COMMAND_SENT (WM_USER + 0x0001)


And to call it from the parent's window procedure:

//...
case WM_COMMAND:
	SendMessage((HWND)lParam, WM_COMMAND_SENT, wParam, 0);
	break;
//...


This way, in the window procedure of the child I can just detect the WM_COMMAND_SENT message and still know what notification was sent from wParam.
However, this doesn't seem a very clean solution.
Does anybody know a better way?

解决方案

If you switch to MFC, then your problem will be simplified too. It supports "Message Reflection": https://msdn.microsoft.com/en-us/library/yef4xasc.aspx.


这篇关于Win32 API:从控件WindowProc中检测WM_COMMAND的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆