Dim Main_hwnd As Long, Edit_hwnd As Long, B_Hwnd As LongMain_hwnd = FindWindow(vbNullString, "打开")
'如记事本的打开选项框
Edit_hwnd = FindWindowEx(Main_hwnd, 0, "ComboBox", "")
'这样这里就获得了第一个下拉列表的句柄
Edit_hwnd = FindWindowEx(Main_hwnd, Edit_hwnd, "ComboBox", "")
'这里却获得了第3个下拉列表的句柄请问各位大侠 如何获得第二个下拉列表的句柄呢?!
'如记事本的打开选项框
Edit_hwnd = FindWindowEx(Main_hwnd, 0, "ComboBox", "")
'这样这里就获得了第一个下拉列表的句柄
Edit_hwnd = FindWindowEx(Main_hwnd, Edit_hwnd, "ComboBox", "")
'这里却获得了第3个下拉列表的句柄请问各位大侠 如何获得第二个下拉列表的句柄呢?!
'以下是编历某个窗口中的子窗口的.你看一下是否有用.
'注意,主要用到的是 GetNextWindowPublic Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As String) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As LongConst GW_HWNDFIRST = 0
Const GW_HWNDLAST = 1
Const GW_HWNDNEXT = 2
Const GW_HWNDPREV = 3
Const GW_OWNER = 4
Const GW_CHILD = 5
Const GW_MAX = 5
Public Function LoadHwnd(ByVal lv As ListView)
Dim hwnd As Long
Dim clsName As String * 127
Dim clsText As String * 127
Dim clsNameLen As Long
Dim TextLen As Long
Dim child_hWnd As Long
Dim Item1 As ListItem
lv.View = lvwReport
lv.ColumnHeaders.Add , , "控件名称"
lv.ColumnHeaders.Add , , "句柄"
lv.ColumnHeaders.Add , , "内容"
hwnd = FindWindow(O&, "fvflove的示例")
clsNameLen = GetClassName(hwnd, clsName, 127)
TextLen = GetWindowTextLength(hwnd)
GetWindowText hwnd, clsText, TextLen + 1
Set Item1 = lv.ListItems.Add(, , Left(clsName, clsNameLen))
Item1.SubItems(1) = hwnd
Item1.SubItems(2) = clsText
child_hWnd = GetWindow(hwnd, GW_CHILD)
Do While child_hWnd <> 0 '如果有子窗口 clsNameLen = GetClassName(child_hWnd, clsName, 127)
TextLen = GetWindowTextLength(child_hWnd)
GetWindowText child_hWnd, clsText, TextLen + 1
Set Item1 = lv.ListItems.Add(, , Left(clsName, clsNameLen))
Item1.SubItems(1) = child_hWnd
Item1.SubItems(2) = clsText
'SetWindowText child_hWnd, "fvf"
child_hWnd = GetWindow(child_hWnd, GW_HWNDNEXT) '取得下一个兄弟窗口的句柄
Loop
End Function