首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

遍历窗体控件有关问题

2012-02-08 
遍历窗体控件问题有一个窗体,上面有十几个Edit子控件,我想通过程序向这些控件中填入内容,我用FindWindow找

遍历窗体控件问题
有一个窗体,上面有十几个Edit子控件,我想通过程序向这些控件中填入内容,我用FindWindow找到了这个窗体句柄,也通过FindWindowEx找到了第一个edit控件的句柄,也通过SendMessage写进了内容去,但是怎么继续查找下一个edit控件的句柄呢?请高手给个示例,比如用一个for循环向这十几个edit控件中输入 "Edit1 "- "Edit10 "的内容,谢谢

[解决办法]
HWND FindWindowEx(

HWND hwndParent,// handle to parent window
HWND hwndChildAfter,// handle to a child window
LPCTSTR lpszClass,// pointer to class name
LPCTSTR lpszWindow// pointer to window name
);
hwndChildAfter
// 看完下面这段楼主就知道该怎么做了吧,
Identifies a child window. The search begins with the next child window in the Z order. hwndChildAfter must be a direct child window of hwndParent, not just a descendant window.
If hwndChildAfter is NULL, the search begins with the first child window of hwndParent.
Note that if both hwndParent and hwndChildAfter are NULL, the function searches all top-level windows.
[解决办法]
hwndChildAfter
Identifies a child window. The search begins with the next child window in the Z order. hwndChildAfter must be a direct child window of hwndParent, not just a descendant window.
If hwndChildAfter is NULL, the search begins with the first child window of hwndParent.
Note that if both hwndParent and hwndChildAfter are NULL, the function searches all top-level windows.

FindWindowEx第二个参数的作用,从这个窗口hwndChildAfter后开始查找。这样便可利用对FindWindowEx的多次调用找到符合条件的所有子窗口。如设为零,表示从第一个子窗口开始搜索
[解决办法]
二楼已经说的很明白了

var h1,h2,h3:HWND;
begin
h1:=FindWindow(nil, 'test ');
if h1=0 then
begin
ShowMessage( '未找到 ');
exit;
end;
h2:=FindWindowEx(h1,0, 'Edit ',nil);//找第一个类型为Edit的子窗体
h3:=FindWindowEx(h1,h2, 'Edit ',nil);//找h1之后的下一个类型为Edit的子窗体

热点排行