WH_CBT Hook - does HCBT_DESTROYWND get called for EVERY window in the hooked thread?

  • Thread starter Thread starter JeremyRuth
  • Start date Start date
J

JeremyRuth

Guest
Hello,

I have WH_CBT Hook that is started via the following (not global):

hShellHook = SetWindowsHookEx(WH_CBT, DLL_HookProc, hThisDll, dwThreadID);

I am attempting to capture all of the HCBT_CREATEWND and HCBT_DESTROYWND messages. As far as I can tell the hook works pretty much as expected. I am able to successfully capture the CREATEWND messages. Specifically, I am looking to subclass a Listbox on a dialog. In the handling of HCBT_CREATEWND, I identify and subclass the Listbox just fine (I think).

My issue: I am trying to capture when the same Listbox is destroyed. Debugging the hook code, I can confirm that the HCBT_DESTROYWND message is NOT being called for the Listbox window. My first question about the CBT hook... is there any reason a closing window would not fire the HCBT_DESTROYWND message? It was my understanding from the documentation that all windows being destroyed would fall through that code:

LRESULT CALLBACK DLL_HookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if(nCode < 0)
return CallNextHookEx(NULL, nCode, wParam, lParam);


if(nCode == HCBT_DESTROYWND)
{
DLL_HookProc_DestroyWnd(nCode, wParam, lParam);
}

else if(nCode == HCBT_CREATEWND)
{
DLL_HookProc_CreateWnd(nCode, wParam, lParam);
}


return CallNextHookEx(NULL, nCode, wParam, lParam);
}

In my subclassed WNDPROC/SUBCLASSPROC (tried both), I tried to capture WM_DESTROY, but the procedure never gets it. It does, however, receive WM_NCDESTROY. When I run Spy++ alongside of my app, Spy++ shows the WM_DESTROY message being sent/received. I have my window procedure logging all messages, and it does not show:


1551764.jpg

Even without my subclassed procedure (hook is active but don't subclass the listbox), the HCBT_DESTROYWND message is not sent for this window. I am confused. Can anyone shed light on why this may be behaving like this?

Thanks.

Continue reading...
 
Back
Top