胡
胡圖崇
Unregistered / Unconfirmed
GUEST, unregistred user!
开始我始终找不到输入文本消息的控件是什幺﹐后来把控件名都写入一个文本文件后﹐发现是RichEdit20A﹐这样才获得了文本输入框的句柄﹐但是消息发出去一条﹐然后没反应了﹐而且发出去的这条信息对方都收不到﹐不知道是什幺原因﹐请高手指点咯<br>以下是我的程序源代码﹕<br><br>unit UQicqSendForm;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, <br>Dialogs,inifiles,<br> StdCtrls, Buttons, ExtCtrls;<br><br>type<br> TFrmMain = class(TForm)<br> btnStart: TButton;<br> btnEnd: TButton;<br> Bevel1: TBevel;<br> Timer: TTimer;<br> edtTime: TEdit;<br> memText: TMemo;<br> Edit1: TEdit;<br> Label1: TLabel;<br> Label2: TLabel;<br> procedure btnStartClick(Sender: TObject);<br> procedure btnEndClick(Sender: TObject);<br> procedure TimerTimer(Sender: TObject);<br> private<br> { Private declarations }<br> FTextHandle: HWND; //qq消息Text句柄<br> FButtonHandle: HWND; //SendText Button's Handle;<br> public<br> { Public declarations }<br> end;<br><br>var<br> FrmMain: TFrmMain;<br><br> <br>implementation<br><br><br>//Fetch sendText's Button<br>//function EnumChildWindowsProc(hwnd: Integer; lparam: Longint):Boolean;stdcall;<br>function GetButtonHandle(hwnd: Integer; lparam: Longint):Boolean; stdcall;<br>var<br> buffer: array[0..255] of Char;<br> buffer1: array[0..255] of Char;<br>begin<br> Result := True;<br> //Fetch aim window's component<br> GetClassName(hwnd,buffer,256);<br> //Find SendText's Button<br> if StrPas(Buffer)='Button' then<br> begin<br> GetWindowText(hwnd,buffer1,100);<br> if buffer1 = '傳送(&S)' then<br> begin<br> PInteger(lparam)^ := hwnd; //Fetch Handle<br> Result:=False; //Break Loop<br> end;<br> end;<br>end;//end of function<br><br>//Fetch SendText's Text handle<br>//function EnumChildWindowsProc(hwnd: Integer; lparam: Longint):Boolean; stdcall;<br>function GetEditHandle(hwnd: Integer; lparam: Longint):Boolean; stdcall;<br>var<br> buffer: array[0..255] of Char;<br> buffer1: array[0..255] of Char;<br>begin<br> Result := True;<br> //Fetch aim window's component<br> GetClassName(hwnd,buffer,256);<br> //Find text's Handle<br> if StrPas(Buffer)='RichEdit20A' then<br> begin<br> GetWindowText(hwnd,buffer1,100);<br> PInteger(lparam)^ := hwnd; //Fetch Text's Handle<br> Result:=False; //Break Loop<br> end; <br>end;//end of function<br><br>{$R *.DFM}<br><br>procedure TfrmMain.btnStartClick(Sender: TObject);<br>var<br> Handle: Integer;<br> tmpHandle: Integer;<br> sendMan:string;<br>begin<br> {取句柄}<br> sendMan:=edit1.Text;<br> Handle := FindWindow(nil,pchar(sendMan)); //就是窗口的Caption<br> if Handle<>0 then<br> begin<br> tmpHandle := Handle;<br> //Loop For Find Button's Handle;<br> EnumChildWindows(Handle,@GetButtonHandle,Integer(@Handle));<br> FButtonHandle := Handle;<br> //Loop For Find SendText's Handle<br> EnumChildWindows(tmpHandle,@GetEditHandle,Integer(@tmpHandle));<br> FTextHandle := tmpHandle;<br> Timer.Interval := StrToInt(edtTime.Text);<br> Timer.Enabled := true;<br> end;<br><br>end;<br><br>procedure TfrmMain.btnEndClick(Sender: TObject);<br>begin<br> Timer.Enabled := false;//關閉定時器<br>end;<br><br>[red]procedure TfrmMain.TimerTimer(Sender: TObject);<br>begin<br><br> //Send Text<br> SendMessage(FTextHandle,WM_SETTEXT,0,Integer(pchar(memText.Text)));<br><br> //SendText Button<br> SendMessage(FButtonHandle,WM_LBUTTONDOWN,0,0);<br> SendMessage(FButtonHandle,WM_LBUTTONUP,0,0);<br>end;[/red]<br><br>end.<br><br>还有﹕假如上面的问题解决了﹐我怎幺解决监听QQ窗口信息呢﹖就象QQ自动回复一样。