Private
Declare Function GetDesktopWindow Lib "user32" () As Integer
Private
Declare Function GetForegroundWindow Lib "user32" () As
Integer
Private
Declare Function GetWindow Lib "user32" (ByVal hwnd As Integer,
ByVal wCmd As Integer) As Integer
Private
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA"
(ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As
Integer) As Integer
Private
Const GW_CHILD = 5
Private
Const GW_HWNDNEXT = 2
Public
Function GetHandle() As Long
Dim tmp As String
Dim hwnd As Long
Dim strTitle As New String(Chr(0),
255)
'用来存储窗口的标题
'取得桌面窗口
hwnd = GetDesktopWindow()
'取得桌面窗口的第一个子窗口
hwnd = GetWindow(hwnd, GW_CHILD)
'通过循环来枚举所有的窗口
Do While hwnd <> 0
'取得下一个窗口的标题,并写入到列表框中
GetWindowText(hwnd, strTitle, Len(strTitle))
If Strings.Left(strTitle, 1) <>
vbNullChar Then
'取得有空字符的窗口标题
tmp = Strings.Left(strTitle, InStr(1, strTitle, vbNullChar))
If Strings.Left(tmp, 12) = "神鬼传奇新篇全球公测版 " Then
GetHandle = hwnd
Exit Do
End If
End If
'调用GetWindow函数,来取得下一个窗口
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
Loop
End
Function
Private
Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
TextBox1.Text = Hex(GetHandle)
End
Sub
End Class
加载中,请稍候......