说明:<br>1、程序运行后注册一个热键CTRL+A<br>2、打开QQ聊天窗口,按下热键CTRL+A,QQ窗口就会出现发送test.txt的信息(我这里用C:/test.txt测试)<br>测试代码如下:<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Controls, Forms, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Edit1: TEdit;<br> procedure FormCreate(Sender: TObject);<br> procedure FormDestroy(Sender: TObject);<br> private<br> { Private declarations }<br> aatom:atom;<br> procedure HotKey(var Msg: TMessage);message WM_HOTKEY;<br> procedure SendFileToQQ;<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>uses<br> Shellapi, ShlObj;<br><br>{$R *.dfm}<br><br>procedure DoDropFiles(Wnd: HWND; Files: TStringList);<br>var<br> Size: Cardinal;<br> DropFiles: PDropFiles;<br> Run: PChar;<br> MemHandle: THandle;<br> I: Integer;<br>begin<br> Size := 0;<br> for I := 0 to Files.Count - 1 do<br> begin<br> Inc(Size, Length(Files) + 1);<br> end;<br> if Size > 0 then<br> begin<br> Inc(Size, 1 + SizeOf(TDropFiles));<br> MemHandle := GlobalAlloc(GMEM_ZEROINIT,Size);<br> DropFiles := GlobalLock(MemHandle);<br> with DropFiles^ do<br> begin<br> pFiles := SizeOf(TDropFiles); <br> pt := Point(0, 0);<br> fNC := False; <br> fWide := False; <br> end;<br> Run := Pointer(DropFiles);<br> Inc(Run, SizeOf(TDropFiles));<br> for I := 0 to Files.Count - 1 do<br> begin<br> StrPCopy(Run, Files);<br> Inc(Run, Length(Files) + 1);<br> end;<br> Run^ := #0;<br> GlobalUnlock(MemHandle);<br> PostMessage(Wnd, WM_DROPFILES, MemHandle, 0);<br> //GlobalFree(MemHandle);<br> end;<br>end;<br><br>procedure TForm1.HotKey(var Msg: TMessage);<br>begin<br> if (msg.LParamHi=$41) and (msg.LParamLo=MOD_CONTROL) then<br> SendFileToQQ;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> aatom:=globaladdatom('my hot key');<br> RegisterHotKey(handle,aatom,MOD_CONTROL,$41);<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br> globalDeleteatom(aatom);<br>end;<br><br>procedure TForm1.SendFileToQQ;<br>var<br> j1: Integer;<br> List: TStringList;<br>begin<br> j1:=FindWindowEx(GetForegroundWindow,0,'#32770',nil);<br><br> Edit1.Text := IntToHex(j1, 8);<br> if (j1>0) then<br> begin<br> List:=TStringList.Create;<br> try<br> List.Add('C:/test.txt');<br> DoDropFiles(j1, List);<br> finally<br> List.Free;<br> end;<br> end;<br>end;<br><br>end.