取得窗体中所有句柄(zt)


 
+++++++++++++++
DELPHI 源代码
+++++++++++++++
// 将下面这两个变量声明为全局变量
MyhWnd:array[1..200] of hWnd;
MyhWndCount:integer=1;
// 这个过程便能够获得主窗体下的全部子窗体句柄
Procedure Tmainform.GethWnd(Dad:hWnd);
var
bakh:hWnd;
begin
bakh:=Getwindow(Dad,GW_CHILD);
while bakh<>0 do
begin
MyhWnd[MyhWndCount]:=bakh;
MyhWndCount:=MyhWndCount+1;
GethWnd(MyhWnd[MyhWndCount-1]);
bakh:=Getwindow(bakh,GW_HWNDNEXT);
end;
end;
++++++++++++
VB 源代码
++++++++++++

’函数、常数、变量声明
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd  
As Long) As Long
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private MyhWnd(200) As Long
Private MyhWndCount As Integer
’----------------------------
’----------------------------
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal  
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SETTEXT = &HC

Private Sub GethWnd(Dad As Long)
Dim Bakh As Long
Bakh = GetWindow(Dad, GW_CHILD)
While Bakh <> 0
MyhWnd(MyhWndCount) = Bakh
MyhWndCount = MyhWndCount + 1
GethWnd (MyhWnd(MyhWndCount - 1))
Bakh = GetWindow(Bakh, GW_HWNDNEXT)
Wend
End Sub 
posted @ 2005-07-26 10:47  JustLive  阅读(455)  评论(0编辑  收藏  举报