如果没有理解错误请将此文件加入到你的 uses之中unit uHackFr;interfaceuses Windows,Messages,Classes,ComCtrls,Forms;procedure HackFr;procedure UnHackFr; implementationuses SysUtils;{ TStubClass }type TStubClass=class class procedure HackClick(Sender:TObject); end;var M:TNotifyEvent; Btn:TToolButton; hk:Integer;function HookPrintB(TB:TToolBar):Boolean;var I:Integer;begin for I:=0 to TB.ControlCount-1 do if CompareStr(TB.Controls.Name,'PrintB')=0then begin Btn:=TToolButton(TB.Controls); Break; end; Result:=Btn=nil; if not Result then begin M:=TNotifyEvent(Btn.OnClick); Btn.OnClick:=TStubClass.HackClick; end;end; function EProp(h:hwnd;strchar;data:integer):LongBool;stdcall;begin if (data<>0) and(Btn=nil)then try Result:=HookPrintB(TToolBar(data)); except Result:=false; end;end;function CallWndProc(code,w,l:integer):integer;stdcall;var PCWPStruct; c:array[0..255]of char;begin if code=HC_ACTION then begin P:=Pointer(l); case P.message of WM_CREATE:begin GetClassName(P.hwnd,c,255); if SameText(c,'TToolBar')then begin Btn:=nil; EnumProps(P.hwnd,@EProp); end; end; end; end else result:=CallNextHookEx(hk,code,w,l);end;class procedure TStubClass.HackClick(Sender: TObject);begin TNotifyEvent(M)(Btn); TForm(Btn.Owner).Close;end;procedure HackFr;begin hk:=SetWindowsHookEx(WH_CALLWNDPROC,@CallWndProc,HInstance,GetCurrentThreadId);end;procedure UnHackFr;begin UnhookWindowsHookEx(hk);end;initialization HackFr;finalization UnHackFr;end.
to:louemusic您好,感谢您帮我,不过我按照您的以上语句,添加到use中,点击预览窗口的打印按钮时,半天没有反映,好些死机,等待了大概4分钟左右,提示如下错误:Project E:/ku/yhbys.exe faulted with message: 'access violation at 0x7c92eddc:write of address 0x00040e74'. Process Stopped. Use Step or Run to continue.请问是何原因,您调试是好的吗?[]