在MFC程序中挂钩窗口创建 [英] Hooking window creation in an MFC program

查看:171
本文介绍了在MFC程序中挂钩窗口创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有什么办法吗?

解决方案

使用 SetWindowHookEx 安装 CBTProc



这里是一些示例代码。只需从程序开始调用 InstallHook(),然后监视 HCBT_CREATEWND 通知代码。您可以通过从文档中返回非零函数来取消创建窗口。

  LRESULT CALLBACK MyCbtHook(int nCode,WPARAM wParam,LPARAM lParam)
{
switch(nCode)
{
case HCBT_CREATEWND:
{
HWND hWnd =
TRACE(正在创建窗口,HWND =%p \\\
,hWnd);
break;
}
}

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

void InstallHook()
{
SetWindowsHookEx(WH_CBT,MyCbtHook,0,GetCurrentThreadId());
}


I want to hook the window creation in an MFC program.

Is there any way to do that?

解决方案

Use SetWindowHookEx to install a CBTProc.

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\n", hWnd);
            break;
        }
    }

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

void InstallHook()
{
    SetWindowsHookEx(WH_CBT, MyCbtHook, 0, GetCurrentThreadId());
}

这篇关于在MFC程序中挂钩窗口创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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