如何获取子窗口句柄(30分)

  • 主题发起人 主题发起人 lyonlu
  • 开始时间 开始时间
L

lyonlu

Unregistered / Unconfirmed
GUEST, unregistred user!
已经获得父窗口句柄,我想获得子窗口句柄,用findwindowex()和getwindow()都不行,请教各位师兄师姐该怎么办?<br><br>HFwnd := FindWindow(nil,'无标题 - 记事本');<br>&nbsp; &nbsp; &nbsp; &nbsp; Hwnd &nbsp;:= GetWindow(HFwnd,GW_CHILD);<br><br>HFwnd := FindWindow(nil,'无标题 - 记事本');<br>&nbsp; &nbsp; &nbsp; &nbsp; Hwnd:=FindWiodowEx(HFwnd,NULL,nil,nil);
 
如果你知道CLASS 及CAPTION,用FindWindowEx是肯定可以的<br>象你第二个,所有参数都传空,当然什么都找不到了。<br><br>另外也可以用EnumChildWindow把所有的子窗口枚举出来,你再一一判断
 
测试没发现问题<br>function EnumChilds(hwnd: HWND; lParam: LPARAM): BOOL; stdcall;<br>var<br>&nbsp; ClassName: Array[0..255] of Char;<br>begin<br>&nbsp; GetClassName(hwnd, @ClassName, 255);<br>&nbsp; ShowMessage(ClassName);<br>&nbsp; Result := True;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; h, c1, c2 : HWND;<br>begin<br>&nbsp; h := FindWindow(Nil, '未定标题 - 记事本');<br>&nbsp; if h = 0 then<br>&nbsp; &nbsp; Exit;<br>&nbsp; EnumChildWindows(h, @EnumChilds, 0);<br><br>&nbsp; c1 := GetWindow(h, GW_CHILD);<br>&nbsp; c2 := FindWindowEx(h, 0, 'Edit', Nil);<br>&nbsp; ShowMessage(Format('%d &nbsp; &nbsp;%d',[c1, c2]));<br>end;<br>
 
难!我也遇到过这样的问题,当时我想得到一个Excel窗体的句柄,用了FindWindow,GetWindow......甚至连遍历进程,得到进程Id后转换为窗口句柄的方法都用上了,还是不行。(当然这个方法是由于进城Id时时变化造成的),然用FindWindow更不可靠,原因在于窗口的标题的不确定以及不能遍历整个当前的窗口说造成的。<br>&nbsp; 所以劝你还是另选一种更为可靠的方法编程吧!
 
我可以用winsight32查到子窗口的class是Edit,<br>HFwnd := FindWindow(nil,'无标题 - 记事本');<br>&nbsp; &nbsp; &nbsp; &nbsp;Hwnd:=FindWiodowEx(HFwnd,0,'Edit',nil); &nbsp;<br>还是不行,我用单步运行,用watch list观察,运行第一行能看到HFwnd的数值,运行第二行就看不到Hwnd的数值。
 
多人接受答案了。
 

Similar threads

I
回复
0
查看
687
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部