是这样的,比方说现在有一个程序要用MessageBox()来显示一个窗口了,我怎么能在这个窗口显示之前,把它消灭,使它显示不出来?
本来是可以用一个Timer来不断检测这个窗口出来没,出来就杀掉,但我听说可以用消息拦截来实现这个效果的,请大家帮个忙(似乎是要用HOOK)。

解决方案 »

  1.   

    HOOK是可以的,检测到此消息窗口创建消息后就销毁
      

  2.   

    SetWindowsHookEx,idHook=WH_CBT.
    code 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.If the hook procedure returns zero, the window is created normally.
      

  3.   

    重写窗口的Defaultwindowproc方法,把想拦截的消息处理代码注销掉。
      

  4.   

    如果是拦截MessageBox,需要Hook MessageBox函数,在User32.dll中有两个版本MessageBoxA和MessageBoxW,分别对应多字节和Unicode版本。
    如果是拦截普通窗口的显示,可以使用WH_CBT类型的消息钩子,按照lxpws(老烦) 的说法。