Click here to Skip to main content
15,910,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);


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
Posted

1 solution

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]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900