11 Font.Name = 'Tahoma' Font.Style = [] OldCreateOrder = False OnCreate = FormCreate OnDestroy = FormDestroy PixelsPerInch = 96 TextHeight = 13 object Button1: TButton Left = 48 Top = 32 Width = 75 Height = 25 Caption = 'Button1' TabOrder = 0 OnClick = Button1Click end object Button2: TButton Left = 144 Top = 32 Width = 75 Height = 25 Caption = 'Button2' TabOrder = 1 OnClick = Button2Click end
object Timer1: TTimer OnTimer = Timer1Timer Left = 128 Top = 8 end end[/code] 例子二:给 DLL 传递数据 DLL 文件: [code=delphi] library MyHook; uses SysUtils, Windows, Messages, Classes; {$R *.res} const WM_MyMessage = WM_USER + 1; {自定义消息} var hook: HHOOK; info: string; h: HWND; {用作外部窗口的句柄} {获取外部窗口的句柄} function SetHWnd(hwnd: HWND): Boolean; stdcall; begin h := hwnd; Result := True; end; function MouseHook(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; begin case wParam of WM_MOUSEMOVE : info := '鼠标位置'; WM_LBUTTONDOWN : info := '按下'; WM_LBUTTONUp : info := '放开'; end; info := Format('%s: %d,%d', [info, PMouseHookStruct(lParam)^.pt.X,
PMouseHookStruct(lParam)^.pt.Y]); {通过消息把数据传递给指定窗口} PostMessage(h, WM_MyMessage, 0, Integer(PChar(info))); Result := CallNextHookEx(hook, nCode, wParam, lParam); end; function SetHook: Boolean; stdcall; const WH_MOUSE_LL =14; begin hook := SetWindowsHookEx(WH_MOUSE_LL, @MouseHook, HInst
ance, 0); Result := hook <> 0; end; function DelHook: Boolean; stdcall; begin Result := UnhookWindowsHookEx(hook); end; exports SetHook, DelHook, MouseHook, SetHWnd; begin end.[/code] 测试代码: [code=delphi] unit Unit1;