[英]Hooking window creation in an MFC program
I want to hook the window creation in an MFC program. 我想在MFC程序中挂接窗口创建。
Is there any way to do that? 有什么办法吗?
Use SetWindowHookEx to install a CBTProc . 使用SetWindowHookEx安装CBTProc 。
Here's some sample code. 这是一些示例代码。 Just call
InstallHook()
from the beginning of your program, and then monitor the HCBT_CREATEWND
notification code. 只需从程序的开头调用
InstallHook()
,然后监视HCBT_CREATEWND
通知代码。 You can cancel window creation by returning nonzero from the function, as described in the docs. 您可以通过从函数返回非零值来取消窗口创建,如docs中所述。
LRESULT CALLBACK MyCbtHook(int nCode, WPARAM wParam, LPARAM lParam)
{
switch(nCode)
{
case HCBT_CREATEWND:
{
HWND hWnd = (HWND)wParam;
TRACE("A window is being created, HWND = %p\n", hWnd);
break;
}
}
return CallNextHookEx( 0, nCode, wParam, lParam );
}
void InstallHook()
{
SetWindowsHookEx(WH_CBT, MyCbtHook, 0, GetCurrentThreadId());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.