我想禁止某些程序窗口的弹出,请大家看LRESULT CALLBACK CallWndRetProcAllKey (int nCode, WPARAM wParam, LPARAM lParam)
{ if(nCode==HCBT_CREATEWND) 

                      LPCBT_CREATEWND pCW =(LPCBT_CREATEWND)lParam;
                      LPCREATESTRUCT pCS =(LPCREATESTRUCT)pCW->lpcs; if(stricmp(pCS->lpszName,"Windows 任务管理器")==0) 
{
return 0L;
}       }
}
BOOL InstallHook() //导出函数
{ g_hhookSysKey = SetWindowsHookEx(WH_CBT,CallWndRetProcAllKey, NULL , GetCurrentThreadId());
return TRUE; //挂钩成功}
结果pCS->lpszName并不是窗口标题,请问如何得到窗口标题?

解决方案 »

  1.   

    全局钩子SetWindowsHookEx最后一个参数用0就可以了,倒数第二个参数使用DLL模块的句柄
      

  2.   

    可以不用钩子的,有一个API可以捕获所有窗体创建消息
      

  3.   

    "全局钩子SetWindowsHookEx最后一个参数用0就可以了,倒数第二个参数使用DLL模块的句柄"
    大哥所言极是,但我碰到一个极奇怪的问题,“windows 任务管理器"怎么也得不到,只得到他的很多子窗口名柄、标题,然后想通过子窗口句柄获取父窗口或主窗口句柄,都得不到,哎,试了好久
      

  4.   

    另外,在回调函数中if(stricmp(pCS->lpszName,"窗口标题")==0) 

    return 0L; 
    } 但窗体还是正常创建了,并不能拦截,不知怎么办
      

  5.   

    HCBT_CREATEWND
    A window is about to be created. The system calls the hook procedure before sending the WM_CREATE or WM_NCCREATE message to the window. If the hook procedure returns a nonzero value, the system destroys the window; the CreateWindow function returns NULL, but the WM_DESTROY message is not sent to the window. If the hook procedure returns zero, the window is created normally.
    At the time of the HCBT_CREATEWND notification, the window has been created, but its final size and position may not have been determined and its parent window may not have been established. It is possible to send messages to the newly created window, although it has not yet received WM_NCCREATE or WM_CREATE messages. It is also possible to change the position in the z-order of the newly created window by modifying the hwndInsertAfter member of the CBT_CREATEWND structure.
      

  6.   

    在窗体创建前获得此消息“windows 任务管理器"无法获取
    能获取的窗体,我直接返回某一值也无法拦截,窗体还是正常创建了
      

  7.   


    "某些"?
    呵呵,任务管理器?干坏事的吧?你要做成全局钩子,得用 section:#pragma data_seg(".shared")
    HHOOK g_hHook = NULL;
    #pragma data_seg()
    #pragma comment(linker, "/section:.shared,rws")