B
birdhzx
Unregistered / Unconfirmed
GUEST, unregistred user!
{简介:就是发个送数据到google earth的经纬度输入的文本框'<br>查了下用的findwindow,sendmessage等操作窗体和消息的api,可以往记事本和自己写的调试程序发送,但google earth的经纬度输入的文本框不可以,我怀疑是不是该软件屏蔽了某些消息。。!!!唉,实在是黔驴技穷了,调试的话,可能要装个google earth }<br>unit Unit1;<br><br>interface <br><br>uses <br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, <br> Spin, StdCtrls; <br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Memo1: TMemo;<br> Button2: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure FormCreate(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> procedure Button2Click(Sender: TObject);<br> protected<br> procedure myshortcut(var message: TMessage); message WM_HOTKEY;<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br> cnt : Integer = 0;<br> jd,wd,fx,sd:real;<br> id:Integer;<br> procedure SetWndText(hWnd: HWND; Text: String);<br> function SetGoogleHandle(Hwnd:THandle;lParam:LParam):boolean;Stdcall;<br> function GetWndText(hWnd: HWND): String;<br> function GetQQWnd(s1,s2:string): HWND;<br><br>implementation<br><br>{$R *.DFM}<br><br><br>function GetWndText(hWnd: HWND): String;<br><br>Var<br><br> Ret:LongInt;<br><br> mTextChar;<br><br> Buf:Integer;<br><br>begin <br><br> Ret:=SendMessage(hWnd,WM_GETTEXTLENGTH,0,0)+1;<br><br> GetMem(mText,Ret); <br><br> try <br><br> Buf:=LongInt(mText);<br><br> SendMessage(hWnd,WM_GETTEXT,Ret,Buf);<br><br> Result:=StrPas(mText);<br><br> finally<br><br> FreeMem(mText,Ret);<br><br> end;<br><br>end;<br>function s2r(s:string):real;<br>var i1,i2:real;<br>begin<br>i1:=strtofloat(copy(s,1,pos('?',s)-1));<br>delete(s,1,pos('?',s));<br>i2:=strtofloat(copy(s,1,pos('?',s)-1));<br> result:=i1+i2/60;<br>end;<br>procedure SetWndText(hWnd: HWND; Text: String);<br><br>Var<br><br> Ret:LongInt;<br><br> mTextChar;<br><br> Buf:Integer;<br><br>begin<br><br> GetMem(mText,Length(Text));<br><br> StrCopy(mText,PChar(Text));<br><br> try<br><br> Buf:=LongInt(mText);<br><br> SendMessage(hWnd,WM_SETTEXT,0,Buf);<br> //postMessage(hWnd,WM_SETTEXT,0,Buf);<br><br> finally <br><br> FreeMem(mText,Length(Text));<br><br> end;<br><br>end;<br>function SetGoogleHandle(Hwnd:THandle;lParam:LParam):boolean;Stdcall;<br>var<br> buffer: array[0..255] of Char;<br> sWindowText: PChar;<br>s1,Msg:string;<br>begin<br><br> Result := True;<br> //得到目标窗口的控件<br> GetClassName(hwnd,buffer,256);<br> s1:=GetWndText(hwnd);<br> //找到目标窗口的目标控件<br> form1.Memo1.Lines.Add(StrPas(buffer)+'----'+s1);<br>//if Pos('COMBO EDIT',UpperCase(s1)) > 0 then //怕是这个名字,试验了不行<br>//if Pos('MFLYCOMBO',UpperCase(s1)) > 0 then //我要改的就是这个下拉输入框<br>//if Pos('MFLYLABEL',UpperCase(s1)) > 0 then // 可气的是,下拉输入框改不了,标签也改不了,<br>//好吧。我把所有的条件去掉,是个控件就改。。。。还是不行<br><br>if Pos('EDIT',UpperCase(buffer)) > 0 then // 但是。。。换成发送数据到 记事本就可以<br> begin<br> form1.Memo1.Lines.Add('纯粹调试show');<br> Cnt:=Cnt+1;<br> Msg:='29.2545N'+' '+'113.1141E';<br> SetWndText(hwnd,Msg);<br>// SendMessage(hWnd,WM_PASTE,0,0);//试验了粘贴也不行,怕它把消息屏蔽了<br> { case Cnt of //这个计数纯粹我偷懒,直接数第几个控件用的,貌似有个api干这个,没时间去查了 <br> 1:SetWindowText(hwnd,pchar(Msg)); //直接用api也不行<br> 2:SetWndText(hwnd,Msg);<br> 3:SetWndText(hwnd,Msg);<br> 4:SetWndText(hwnd,Msg);<br> 5:SetWndText(hwnd,Msg);<br> 6:SetWndText(hwnd,Msg);<br> else<br> begin<br> // Cnt:=0;<br> //SetWindowText(hwnd,pchar(Msg));<br> //SetWndText(hwnd,Msg);<br> end;<br> end; }<br><br> if Cnt=100 then<br> Result:=False; //终止循环<br> end;<br>end;<br>function GetQQWnd(s1,s2:string): HWND;<br><br>var<br><br> hCurrentWindow: HWnd;<br><br> WndText:String;<br><br>begin<br><br> hCurrentWindow := GetWindow(Application.Handle, GW_HWNDFIRST);<br><br> while hCurrentWindow> 0 do<br><br> begin<br><br> WndText:=GetWndText(hCurrentWindow);<br><br><br> if (Pos(s1,WndText)>0) or (Pos(s2,WndText)>0) then<br><br> begin<br><br> WndText:=GetWndText(hCurrentWindow);<br> Result:=hCurrentWindow;<br><br> Exit; <br><br> end;<br><br> hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);<br><br> end;<br><br> Result:=0;<br><br>end;<br><br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>id:=GlobalAddAtom('hotkey');<br><br>RegisterHotKey(handle,id,mod_control,$51);<br> cnt:=0;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>UnRegisterHotKey(handle,id); //别忘了在退出时取消定义<br>end;<br><br>procedure TForm1.myshortcut(var message: TMessage);<br>begin<br> Caption:='你好,Crtl + Q 被按下'+datetimetostr(now);<br> Button1.Click;<br>end;<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> Handle: Integer;<br>begin<br> //------------------------------发送数据到google earth<br> {取句柄}<br> //Handle:=GetQQWnd('QWidget','Google Earth');//可能要麻烦大哥们装个Google Earth了,不试验是不知道滴<br> //Handle:=GetQQWnd('Form111','Form111');//可以发送数据到 自己写的测试窗口<br> Handle:=GetQQWnd('记事本','记事本');// 也发送数据到 记事本也可以 ,大家记事本就不用装了。。<br><br> if Handle=0 then Exit;<br> BringWindowToTop(Handle);<br> if Handle>0 then<br> begin<br> //在这里循环取到想要的句柄为止<br> EnumChildWindows(Handle,@SetGoogleHandle,Integer(@Handle));<br> //此时,Handle就是你要的句柄<br> end;//end of if }<br><br>end;<br>procedure TForm1.Button2Click(Sender: TObject);<br>var<br> Handle: Integer;<br>begin<br> //------------------------------发送数据到google earth<br> {取句柄}<br> Handle:=GetQQWnd('QWidget','Google Earth');//可能要麻烦大哥们装个Google Earth了,<br> // 不试验是不知道滴 它不大,20来M吧,装了你不会舍得删的,下载地址去搜吧,偶给链接会有带病嫌疑。。<br> //Handle:=GetQQWnd('Form111','Form111');//可以发送数据到 自己写的测试窗口<br> //Handle:=GetQQWnd('记事本','记事本');// 也发送数据到 记事本也可以 ,大家记事本就不用装了。。<br><br> if Handle=0 then<br> begin<br> ShowMessage('不试验是不知道滴 google earth不大,20来M吧,装了你不会舍得删的,下载地址去搜吧,偶给链接会有带病毒嫌疑。兄弟救救偶吧,就是发个送数据到google earth的经纬度输入的文本框');<br> Exit;<br> end;<br> BringWindowToTop(Handle);<br> if Handle>0 then<br> begin<br> //在这里循环取到想要的句柄为止<br> EnumChildWindows(Handle,@SetGoogleHandle,Integer(@Handle));<br> //此时,Handle就是你要的句柄<br> end;//end of if }<br><br>end;<br><br>end.