//dll<br>library Hook;<br><br>uses<br> SysUtils,<br> Classes,<br> HookProc in 'HookProc.pas';<br><br>{$R *.RES}<br><br>exports<br> SetHook,<br> EndHook,<br> SetHandled;<br><br>begin<br> IntoShare;<br>end.<br><br>//dll proc.pas<br>unit HookProc;<br><br>interface<br><br>uses<br> SysUtils,<br> Classes,<br> Windows,<br> Dialogs,<br> Messages;<br><br>function MyCBTHookProc(nCode: Integer; wp: wParam; lp: lParam): LResult; stdcall;<br>procedure SetHook;export;<br>procedure EndHook;export;<br>procedure IntoShare; stdcall;export;<br>procedure SetHandled( H: THandle );stdcall; export;<br><br>implementation<br><br>type<br> TGoData = record<br> TargetWnd : Hwnd;<br> ghHook : HHook;<br> end;<br> PGoData = ^TGoData;<br><br>{const<br> TARGET_WND_TITLE = '我的文档'; }<br><br>var<br> GoData : PGoData;<br> MemFile : THandle;<br><br>procedure SetHandled( H: THandle );stdcall; export;<br>begin<br> GoData^.TargetWnd := H;<br> if GoData^.TargetWnd <> 0 then<br> MessageBeep(0);<br>end;<br><br>function MyCBTHookProc(nCode: Integer; wp: wParam; lp: lParam): LResult; stdcall;<br>{const<br> TargetFocused : Boolean = False; }<br>begin<br>{ if ( nCode = HCBT_ACTIVATE ) then<br> begin<br> GoData^.TargetWnd := FindWindow( nil, PChar( TARGET_WND_TITLE ));<br> if GoData^.TargetWnd <> 0 then<br> TargetFocused := True;<br> end;<br><br> Result := CallNextHookEx( GoData^.ghHook, nCode, wP, lP); }<br> if ( nCode = HCBT_ACTIVATE ) then<br> begin<br> // MessageBeep(0);<br> if {(nCode = HCBT_SYSCOMMAND) and} ( PMsg(lp)^.Message = WM_CLOSE) and ( GoData^.TargetWnd = PMsg(lP)^.hwnd ) then<br> begin<br> MessageBeep(0);<br> ShowWindow( GoData^.TargetWnd, SW_SHOWMINIMIZED );<br> end;<br> end;<br> Result := CallNextHookEx( GoData^.ghHook, nCode, wP, lP);<br>end;<br><br>procedure SetHook;export;<br>begin<br> GoData^.ghHook := SetWindowsHookEx( WH_CBT, @MyCBTHookProc, hInstance, 0);<br>end;<br><br>procedure EndHook;export;<br>begin<br> UnhookWindowsHookEx( GoData^.ghHook );<br>end;<br><br>procedure IntoShare; stdcall;export;<br>begin<br> MemFile := OpenFileMapping( FILE_MAP_WRITE, False, 'JJYY' );<br> if MemFile = 0 then<br> MemFile:=CreateFileMapping( $FFFFFFFF, nil,<br> PAGE_READWRITE, 0, SizeOf( TGoData ), 'JJYY');<br> GoData := MapViewOfFile( MemFile, FILE_MAP_WRITE, 0, 0, 0 );<br> if MemFile = 0 then<br> FillChar( GoData^, SizeOf( TGoData ),0);<br>end;<br><br>end.<br><br>//调用<br>procedure SetHandled( H : THandle ); stdcall;<br>external 'Hook.dll';<br><br>procedure SetHook; stdcall;<br>external 'Hook.dll';<br><br>procedure EndHook; stdcall;<br>external 'Hook.dll';<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> H : THandle;<br>begin<br> H := FindWindow( nil, 'Test' );<br> if H <> 0 then ShowMessage( 'H<>0' );<br> SetHandled( H );<br> SetHook;<br>end;<br><br>请高手相助,嫌分不够可再加!!!!!