关于SENDMESSAGE和POSTMESSAGE的发送问题!~~~~~~~~~~ ( 积分: 150 )

  • 主题发起人 主题发起人 LDSON
  • 开始时间 开始时间
当然用postmessage发送咯,<br>但是需要用类似刘麻子的DFSrc_OkToDrop的方法来判断,目标程序的哪个窗口能够AcceptFile.
 
|----#32770&lt;-------------------------------你需要给这个发消息才行<br><br>已经照做了,什么反应也没有,你是否能帖个完整的代码?麻子兄的代码过长还未细看,才回到家,先谢谢各位了
 
说明:<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> &nbsp;Windows, Messages, SysUtils, Classes, Controls, Forms, StdCtrls;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Edit1: TEdit;<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp; &nbsp;procedure FormDestroy(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp; &nbsp;aatom:atom;<br> &nbsp; &nbsp;procedure HotKey(var Msg: TMessage);message WM_HOTKEY;<br> &nbsp; &nbsp;procedure SendFileToQQ;<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br>uses<br> &nbsp;Shellapi, ShlObj;<br><br>{$R *.dfm}<br><br>procedure DoDropFiles(Wnd: HWND; Files: TStringList);<br>var<br> &nbsp;Size: Cardinal;<br> &nbsp;DropFiles: PDropFiles;<br> &nbsp;Run: PChar;<br> &nbsp;MemHandle: THandle;<br> &nbsp;I: Integer;<br>begin<br> &nbsp;Size := 0;<br> &nbsp;for I := 0 to Files.Count - 1 do<br> &nbsp;begin<br> &nbsp; &nbsp;Inc(Size, Length(Files) + 1);<br> &nbsp;end;<br> &nbsp;if Size &gt; 0 then<br> &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;Inc(Size, 1 + SizeOf(TDropFiles));<br> &nbsp; &nbsp; &nbsp; &nbsp;MemHandle := GlobalAlloc(GMEM_ZEROINIT,Size);<br> &nbsp; &nbsp;DropFiles := GlobalLock(MemHandle);<br> &nbsp; &nbsp; &nbsp; &nbsp;with DropFiles^ do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;pFiles := SizeOf(TDropFiles); <br> &nbsp; &nbsp; &nbsp;pt := Point(0, 0);<br> &nbsp; &nbsp; &nbsp;fNC := False; &nbsp;<br> &nbsp; &nbsp; &nbsp;fWide := False; <br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;Run := Pointer(DropFiles);<br> &nbsp; &nbsp;Inc(Run, SizeOf(TDropFiles));<br> &nbsp; &nbsp;for I := 0 to Files.Count - 1 do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;StrPCopy(Run, Files);<br> &nbsp; &nbsp; &nbsp;Inc(Run, Length(Files) + 1);<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;Run^ := #0;<br> &nbsp; &nbsp;GlobalUnlock(MemHandle);<br> &nbsp; &nbsp;PostMessage(Wnd, WM_DROPFILES, MemHandle, 0);<br> &nbsp; &nbsp;//GlobalFree(MemHandle);<br> &nbsp;end;<br>end;<br><br>procedure TForm1.HotKey(var Msg: TMessage);<br>begin<br> &nbsp;if (msg.LParamHi=$41) and (msg.LParamLo=MOD_CONTROL) then<br> &nbsp; &nbsp;SendFileToQQ;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> &nbsp;aatom:=globaladdatom('my hot key');<br> &nbsp;RegisterHotKey(handle,aatom,MOD_CONTROL,$41);<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br> &nbsp;globalDeleteatom(aatom);<br>end;<br><br>procedure TForm1.SendFileToQQ;<br>var<br> &nbsp;j1: Integer;<br> &nbsp;List: TStringList;<br>begin<br> &nbsp;j1:=FindWindowEx(GetForegroundWindow,0,'#32770',nil);<br><br> &nbsp;Edit1.Text := IntToHex(j1, 8);<br> &nbsp;if (j1&gt;0) then<br> &nbsp;begin<br> &nbsp; &nbsp;List:=TStringList.Create;<br> &nbsp; &nbsp;try<br> &nbsp; &nbsp; &nbsp;List.Add('C:/test.txt');<br> &nbsp; &nbsp; &nbsp;DoDropFiles(j1, List);<br> &nbsp; &nbsp;finally<br> &nbsp; &nbsp; &nbsp;List.Free;<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br>end;<br><br>end.
 
关于下面这一行说明一下:<br>j1:=FindWindowEx(GetForegroundWindow,0,'#32770',nil);<br><br>GetForegroundWindow就是取得聊天窗口的主窗口<br>j1就是我上面说的窗口<br><br>QQ聊天窗口的结构:<br>-----#32770--与 XXX 交谈中---------------GetForegroundWindow<br> &nbsp; &nbsp; &nbsp; &nbsp;|----BUTTON---(最小化)<br> &nbsp; &nbsp; &nbsp; &nbsp;|----BUTTON---(最大化)<br> &nbsp; &nbsp; &nbsp; &nbsp;|----BUTTON---(关 &nbsp;闭)<br> &nbsp; &nbsp; &nbsp; &nbsp;|----#32770&lt;----------------------这就是j1--你需要给这个发消息才行<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|----RichEdit20A----消息显示窗口<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|----AfxWnd42<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp;|----RICHEDIT---消息输入窗口<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp;...<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;...
 
独帅 真不好意思是我把句柄写成另一个样子才不成功,多谢指教了,分已经发出
 
多人接受答案了。
 
后退
顶部