spy ++和WM_PAINT [英] spy++ and WM_PAINT

查看:140
本文介绍了spy ++和WM_PAINT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个带有聊天框控件的第三方应用程序,并且我希望每次更新聊天框时都将焦点放在父窗口上.
我检查了spy ++,发现每次添加新行时,控件都会收到P WM_PAINT.

我尝试自己挂接它(通过挂接WH_GETMESSAGE),并在每次收到WM_PAINT时写入日志,但是即使spy ++显示活动,日志也没有显示任何内容.

我认为这样做的原因是我检查了消息是否属于控件,并且在写入日志之前确实是WM_PAINT,而我执行此操作的方式是通过解析lParam的值:

Hello,

I have a 3rd party application with a chat box control, and I want to focus the parent window every time the chat box is updated.
I checked with spy++, and saw that the control receives P WM_PAINT every time a new line is added.

I tried hooking it myself (by hooking WH_GETMESSAGE) and writing to the log every time WM_PAINT is received, however the log showed nothing, even though spy++ showed activity.

I assume that the reason for that is that I checked if the message belongs to the control, and that it is indeed WM_PAINT before writing it the log, and the way I did it was by parsing the value of lParam:

CWPSTRUCT* cwps = (CWPSTRUCT*)lParam;
if ((cwps->hwnd != mWindowID) || (cwps->message != WM_PAINT))
  return CallNextHookEx(key, nCode, wParam, lParam);



有道理,上述条件不会通过,例如,如果lParam为null,这恰好是spy ++对每条WM_PAINT消息接收显示的内容.

所以我的问题是:
spy ++如何知道特定控件在没有lParam的情况下收到WM_PAINT消息?

预先感谢,
Elad



It makes sense that the above condition will not pass, if for example lParam is null, which is EXACTLY what spy++ showed for every WM_PAINT message receives.

So my question is:
How does spy++ know that the specific control received a WM_PAINT message without the lParam?

Thanks in advance,
Elad

推荐答案

问题已解决.
挂钩到WH_GETMESSAGE时,应该将lParam强制转换为MSG而不是CWPSTRUCT(我复制代码的示例是挂钩WH_CALLWNDPROC,后来我将其更改为WH_GETMESSAGE而不更改Proc代码).

用MSG替换CWPSTRUCT之后,我得到了所有WM_PAINT.

如果不是一直显示lParam NULL的间谍++,我可能会早点解决这个问题:
Problem solved.
When hooking to WH_GETMESSAGE the lParam should be cast to MSG and not CWPSTRUCT (the example I copied the code from was hooking WH_CALLWNDPROC and I changed it later to WH_GETMESSAGE without changing the Proc code).

After replacing CWPSTRUCT with MSG I got all the WM_PAINTs.

I would probably have solved this alot sooner if it wasn''t for the spy++ who kept showing lParam NULL:
<00006> 000903E6 P WM_PAINT hdc:00000000 [wParam:00000000 lParam:00000000]
<00007> 000903E6 P WM_PAINT hdc:00000000 [wParam:00000000 lParam:00000000]
<00008> 000903E6 P WM_PAINT hdc:00000000 [wParam:00000000 lParam:00000000]
<00009> 000903E6 P WM_PAINT hdc:00000000 [wParam:00000000 lParam:00000000]
<00010> 000903E6 P WM_PAINT hdc:00000000 [wParam:00000000 lParam:00000000]
<00011> 000903E6 P WM_PAINT hdc:00000000 [wParam:00000000 lParam:00000000]
<00012> 000903E6 P WM_PAINT hdc:00000000 [wParam:00000000 lParam:00000000]


这篇关于spy ++和WM_PAINT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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