我取得了窗体的句柄,但是他里面的一个控件caption为空,class会变,如何取这个控件句柄(200分)

  • 主题发起人 主题发起人 冬月
  • 开始时间 开始时间

冬月

Unregistered / Unconfirmed
GUEST, unregistred user!
我取得了窗体的句柄,但是他里面的一个控件caption为空,class会变[每次都不一样],如何取这个控件句柄,代码如下<br>&nbsp;hParent:=FindWindow(nil,pChar('Form1'));<br>&nbsp;hParent:=FindWindowEx(hParent,0,PChar('??????'),'');<br>我第2句该如何填才能取到该控件的句柄?
 
你用getnextwindows(hparent,GW_HWNDNEXT);来找
 
举个例子
 
class会变<br>感觉不太可能吧
 
FindWindowEx()<br>用这个来取得子窗体.
 
unit findw;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; wnd,twnd:HWND;<br>&nbsp; ss:array[0..255] of char;<br>&nbsp; i:integer;<br>&nbsp; dcc:HDC;<br>implementation<br><br>{$R *.dfm}<br>procedure FWindow(var WND:HWND);<br>begin<br>&nbsp; GetWindowText(WND,@ss,255);<br>&nbsp; if copy(string(ss),0,16) = '边锋网络游戏世界' then<br>&nbsp; begin<br>&nbsp; &nbsp; WND:=FindWindowEx(WND,0,'MDIClient',nil);<br>&nbsp; &nbsp; for i:=1 to 3 do<br>&nbsp; &nbsp; &nbsp; WND:=GetWindow(WND,GW_CHILD);<br>&nbsp; &nbsp; GetClassName(WND,@ss,255);<br>&nbsp; &nbsp; Showmessage(string(ss));<br>&nbsp; end;<br>&nbsp; WND:=GetNextWindow(WND,GW_HWNDNEXT);<br>&nbsp; if WND &lt;&gt; 0 then FWindow(WND);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; twnd:=GetWindow(GetDesktopWindow(),GW_CHILD);<br>&nbsp; FWindow(twnd);<br>end;<br><br>end.
 
接受答案了.
 
unit unit7;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls, ComCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; TreeView1: TTreeView;<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; str:array[0..255] of char;<br>&nbsp; twnd,wnd:HWND;<br>&nbsp; tv:TTreeNode;<br>implementation<br><br>{$R *.dfm}<br>procedure TForm1.Button1Click(Sender: TObject);<br>&nbsp; procedure FWindow(wnd:HWND;tv:TTreeNode);<br>&nbsp; var<br>&nbsp; &nbsp; tv1:TTreeNode;<br>&nbsp; &nbsp; swnd:HWND;<br>&nbsp; begin<br>&nbsp; &nbsp; GetClassName(wnd,@str,255);<br>&nbsp; &nbsp; tv1 :=TreeView1.Items.AddChild(tv,String(str));<br>&nbsp; &nbsp; if GetWindow(wnd,GW_CHILD) &lt;&gt; 0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; swnd:=GetWindow(wnd,GW_CHILD);<br>&nbsp; &nbsp; &nbsp; FWindow(swnd,tv1);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; swnd:=GetNextWindow(wnd,GW_HWNDNEXT);<br>&nbsp; &nbsp; if swnd &lt;&gt; 0 then FWindow(swnd,tv);<br>&nbsp; end;<br>begin<br>&nbsp; twnd:=GetDesktopWindow();<br>&nbsp; FWindow(twnd,tv);<br>end;<br><br>end.<br>
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部