写其他程序文本框不可行,简易,有源码,帮调下,谢谢,在线等,急 ( 积分: 200 )

  • 主题发起人 主题发起人 birdhzx
  • 开始时间 开始时间
B

birdhzx

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