如何监测出 指定标题的窗口的创建, 并在窗口显示前杀掉它,不让它显示? :)(100分)

  • 主题发起人 主题发起人 netkstar
  • 开始时间 开始时间
N

netkstar

Unregistered / Unconfirmed
GUEST, unregistred user!
如何监测出 指定标题的窗口的创建, 并在窗口显示前杀掉它,不让它显示?
 
非要在显示前的话,就HOOK CREATEWINDOW吧。
 
白大侠: <br>&nbsp; &nbsp; 高手出现,能否详解迷津,再加100分! 先谢了 :)
 
大侠?还是算了吧,非常麻烦的事情。<br>你可以先用TRW跟一下createwindow的过程,<br>然后在你的程序运行后找到内存总相应的地址段,<br>把它的其中一个语句改掉, jmp 到你自己的程序去,<br>然后最后再返回.<br>如果不懂汇编的话........
 
汇编是高深,那么用hook 怎么实现?
 
上面不就说了吗?
 
有没有代码范例?
 
用得了findwindow就不叫"在窗口显示前"了。
 
hook 窗口创建信息。不过很麻烦
 
有没有更深入的大侠?
 
这个不是深不深入的问题了,想用就自己用TRW跟吧。<br>难道你想别人做好一个完整的给你?<br>这就失去了来DELPHIBBS的目的了。
 
to baihechou<br><br>那倒不必,不知道你能否具体讲述用hook的方法?
 
在加一百分,寻高手详解!
 
Hook,Hook,Hook,Hook,CBT_HOOK!<br>具体说明参见windows sdk help.<br>在win2k+delphi6下测试通过。<br><br>建立1个dll:<br>//-----------START------------<br>library Unit1;<br>//保存project为sample<br><br>uses<br>&nbsp; SysUtils,<br>&nbsp; Classes,<br>&nbsp; windows,<br>&nbsp; messages;<br><br>var<br>&nbsp; hNextHookProc:cardinal;<br><br>{$R *.RES}<br><br>function HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;<br>begin<br>&nbsp; result:=0;<br>&nbsp; if iCode&lt;0 then<br>&nbsp; begin<br>&nbsp; &nbsp; CallNextHookEx(hnexthookproc,iCode,wParam,lParam);<br>&nbsp; &nbsp; result:=0;<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br>&nbsp; if (icode=HCBT_CREATEWND) then &nbsp;//创建窗口<br>&nbsp; begin<br>&nbsp; if CBT_CREATEWND(pointer(lparam)^).lpcs^.hwndParent=0 then<br>&nbsp; &nbsp; if CBT_CREATEWND(pointer(lparam)^).lpcs^.lpszName='QQ' then<br>&nbsp; &nbsp; //如果启动的是QQ,则result:=1,拒绝创建窗口。<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; messagebeep(0);<br>&nbsp; &nbsp; &nbsp; result:=1;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>procedure sethook;<br>begin<br>&nbsp; messagebeep(0);<br>&nbsp; if hnexthookproc&lt;&gt;0 then exit;<br>&nbsp; hNextHookProc := SetWindowsHookEx(WH_CBT,hookproc,HInstance,0);<br>end;<br><br>procedure unhook;<br>begin<br>&nbsp; if not UnhookWindowshookEx(hNextHookProc) then<br>&nbsp; &nbsp; hNextHookProc:=0;<br>end;<br><br>exports<br>&nbsp; sethook,<br>&nbsp; unhook;<br><br>begin<br><br>end.<br>//-----------END--------------<br>在建立一个新application:<br>Form1上添加1按钮,代码如下:<br>//-----------START--------------<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>&nbsp; procedure sethook;external 'sample.dll';<br>&nbsp; procedure unhook;external 'sample.dll';<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; SetHook;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>&nbsp; UnHook;<br>end;<br>//-----------END--------------
 
哈阿哈,高手出现,先谢了 :)
 
不要hook createWindow,最好hook showwindow或者让createwidow建立隐藏窗口.因为好多程序不检查createwindow的返回结果<br>要是createwindow没有创建对象,以后每次对这个对象的操作都会非法.
 

Similar threads

S
回复
0
查看
816
SUNSTONE的Delphi笔记
S
S
回复
0
查看
733
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部