delphi程序中如何访问其它正在运行程序的控件信息?比如说状态栏(100分)

  • 主题发起人 主题发起人 隐天
  • 开始时间 开始时间

隐天

Unregistered / Unconfirmed
GUEST, unregistred user!
[:)]<br>我现在只是用手工输入在屏幕中看到的信息,很麻烦,如果可以直接从那个程序的状态栏读取数据就好了
 
我以取得写字板状态栏文字为例,做了一个程序供参考。<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; h:THandle;<br>&nbsp; tmpStr:array[0..255] of char;<br>&nbsp; MyText:String;<br>begin<br>&nbsp; h:=Findwindow(nil,'文档 - 写字板');<br>&nbsp; h:=GetWindow(h,GW_Child);<br>&nbsp; while h&lt;&gt;0 &nbsp;do<br>&nbsp; begin<br>&nbsp; &nbsp; getclassName(h,tmpstr,255);<br>&nbsp; &nbsp; if pos('status', lowercase(strpas(tmpstr)))&gt;0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; sendmessage(h,wm_gettext,256,integer(@tmpstr));<br>&nbsp; &nbsp; &nbsp; showmessage(strpas(tmpstr)); &nbsp;//最后结果<br>&nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; h:=GetWindow(h,GW_HWNDNext);<br>&nbsp; end;<br>end;
 
华旗的产品-爱国者MP3很烂,才用20天,耳机就脱胶,还说是外伤,不给任何维修等,哪个龟儿子再买爱国者MP3,甚至华旗的东西<br><br>如果不属实,天洙地灭
 
试试这个:<br><br><br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, ExtCtrls, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; NameLB: TLabel;<br>&nbsp; &nbsp; ClassLB: TLabel;<br>&nbsp; &nbsp; Timer1: TTimer;<br>&nbsp; &nbsp; Memo1: TMemo;<br>&nbsp; &nbsp; procedure Timer1Timer(Sender: TObject);<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; procedure GetMousePosHwndAndClassName(Sender : TPoint);<br>&nbsp; public<br>&nbsp; end;<br><br>var Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var rPos: TPoint;<br>begin<br>&nbsp; if boolean(GetCursorPos(rPos))<br>&nbsp; then GetMousePosHwndAndClassName(rPos);<br>end;<br><br>procedure TForm1.GetMousePosHwndAndClassName(Sender: TPoint);<br>var hWnd: THandle;<br>&nbsp; &nbsp; aName: array [0..255] of char;<br>begin<br>&nbsp; hWnd := WindowFromPoint(Sender);<br>&nbsp; NameLB.Caption := 'Handle:' + IntToStr(hWnd);<br><br>&nbsp; if boolean(GetClassName(hWnd, aName, 256)) then<br>&nbsp; begin<br>&nbsp; &nbsp; ClassLB.Caption := 'ClassName : ' + string(aName);<br>&nbsp; &nbsp; if Memo1.Lines[Memo1.Lines.Count-1]&lt;&gt;string(aName)<br>&nbsp; &nbsp; then Memo1.Lines.Add(string(aName));<br>&nbsp; end else ClassLB.Caption := 'ClassName : not found';<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; Form1.FormStyle := fsStayOnTop;<br>&nbsp; Timer1.Interval := 50;<br>end;<br><br>end.<br><br><br><br><br>
 
watsonyin的这个我试了一下,可以取,现在只看那个程序是否也可以这样了。 +100分<br>quark的这个,不知道怎么用?程序运行后怎么样得到状态栏信息?
 

Similar threads

D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
893
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部