Private Declare Function GetDlgItem Lib "user32" (ByVal hDlg As Long, ByVal nIDDlgItem As Long) As Long
Private Declare Function SendMessage& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Private Declare Function SendMessageBynum& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Private Declare Function SendMessageByString& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public str As String, nmb As String, qqhwnd As Long, pwdhwnd As Long, temp As Long, numberhwnd As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Sub Command1_Click()
str = String(80, 0)
qqhwnd = FindWindow(vbNullString, "Fetion 2006 Beta")
Text1.Text = Hex(qqhwnd)
End Sub
Private Sub Command2_Click()
Dim numberhwnd As Long
Dim kk As String
If qqhwnd <> 0 Then
kk = "3e9"
numberhwnd = GetDlgItem(qqhwnd, kk) '得到用户号码框的名柄
Text2.Text = numberhwnd
DoEvents
End If
Option Explicit
Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim h As Long, strArr() As String, pid As Long, i As Integer
If InStr(GetWindowCaption(hwnd), "辉煌在线管理团队 - 群") Then
FindControlHwndByClsName hwnd, "SysListView32", h
GetWindowThreadProcessId hwnd, pid
If h <> 0 Then
strArr = GetListViewTextArray(h, pid)
For i = 0 To UBound(strArr)
MsgBox strArr(i)
Next
End If
End If
EnumWindowsProc = True
End Function
Private Function GetWindowCaption(ByVal hwnd As Long) As String
Dim strText As String, ret As Long
ret = GetWindowTextLength(hwnd)
If ret > 0 Then
strText = Space(ret)
GetWindowText hwnd, strText, ret + 1
strText = Left(strText, ret)
GetWindowCaption = strText
Else
GetWindowCaption = ""
End If
End Function
Private Function FindControlHwndByCaption(ByVal nHwnd As Long, ByVal findStr As String, outHwnd As Long)
Dim fHwnd As Long, myStr As String, sHwnd As Long
fHwnd = GetWindow(nHwnd, GW_CHILD)
If fHwnd = 0 Then Exit Function
Do While fHwnd > 0
myStr = String(100, Chr$(0))
GetWindowText fHwnd, myStr, 100
If Left(myStr, InStr(myStr, Chr$(0)) - 1) = findStr Then
outHwnd = fHwnd
Exit Function
End If
sHwnd = GetWindow(fHwnd, GW_CHILD)
If sHwnd > 0 Then
FindControlHwndByCaption fHwnd, findStr, outHwnd
End If
fHwnd = GetWindow(fHwnd, GW_HWNDNEXT)
Loop
End Function
Private Function FindControlHwndByClsName(ByVal nHwnd As Long, ByVal clsName As String, outHwnd As Long)
Dim fHwnd As Long, myStr As String, sHwnd As Long, ret As Long, iss As Boolean
fHwnd = GetWindow(nHwnd, GW_CHILD)
If fHwnd = 0 Then Exit Function
Do While fHwnd > 0
myStr = String(100, Chr$(0))
GetClassName fHwnd, myStr, 100
If Left(myStr, InStr(myStr, Chr$(0)) - 1) = clsName Then
outHwnd = fHwnd
Exit Function
End If
sHwnd = GetWindow(fHwnd, GW_CHILD)
If sHwnd > 0 Then
FindControlHwndByClsName fHwnd, clsName, outHwnd
End If
fHwnd = GetWindow(fHwnd, GW_HWNDNEXT)
Loop
End Function
声明:
private Declare Function GetDlgItem Lib "user32" (ByVal hDlg As Long, ByVal nIDDlgItem As Long) As Long
调用:
dim mhwnd as long
mhwnd=GetDlgItem(窗口句柄,控件ID号)