Hooking window creation in an MFC program(在 MFC 程序中创建挂钩窗口)
问题描述
我想在 MFC 程序中挂钩窗口创建.
I want to hook the window creation in an MFC program.
有什么办法吗?
推荐答案
使用SetWindowHookEx 来安装 CBTProc.
这里有一些示例代码.只需从程序开头调用 InstallHook(),然后监视 HCBT_CREATEWND 通知代码.您可以通过从函数返回非零值来取消窗口创建,如文档中所述.
Here's some sample code. Just call InstallHook() from the beginning of your program, and then monitor the HCBT_CREATEWND notification code. You can cancel window creation by returning nonzero from the function, as described in the 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
", hWnd);
            break;
        }
    }
    return CallNextHookEx( 0, nCode, wParam, lParam );
}
void InstallHook()
{
    SetWindowsHookEx(WH_CBT, MyCbtHook, 0, GetCurrentThreadId());
}
                        这篇关于在 MFC 程序中创建挂钩窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 MFC 程序中创建挂钩窗口
				
        
 
            
        基础教程推荐
- 在 C++ 中计算滚动/移动平均值 2021-01-01
 - 如何在 C++ 中初始化静态常量成员? 2022-01-01
 - C++结构和函数声明。为什么它不能编译? 2022-11-07
 - 如何通过C程序打开命令提示符Cmd 2022-12-09
 - 我有静态或动态 boost 库吗? 2021-01-01
 - 如何检查GTK+3.0中的小部件类型? 2022-11-30
 - 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
 - 这个宏可以转换成函数吗? 2022-01-01
 - 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
 - 常量变量在标题中不起作用 2021-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				