mm: greater than 32 if successful, or an error value that is less than or equal to 32 otherwise.
Option ExplicitPrivate Const WM_CLOSE = &H10 Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Sub EndFun() On Error GoTo ErrTrap
Dim hwnd As Long Dim i As Long Dim WinNm As String
WinNm = "about:blank - Microsoft Internet Explorer" hwnd = FindWindow(vbNullString, WinNm) If hwnd <> 0 Then i = PostMessage(hwnd, WM_CLOSE, 0, 0)
GoTo WayOut ErrTrap: WayOut: End SubPrivate Sub Form_Load() EndFun End Sub
Private Declare Function FindWindowLong Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wcmd As Long) As LongPrivate Function InstanceToWnd(ByVal target_pid As Long) As Long Dim test_hwnd As Long Dim test_pid As Long Dim test_thread_id As Long ' Get the first window handle. test_hwnd = FindWindowLong(ByVal 0&, ByVal 0&) ' Loop until we find the target or we run out ' of windows. Do While test_hwnd <> 0 ' See if this window has a parent. If not, ' it is a top-level window. If GetParent(test_hwnd) = 0 Then ' This is a top-level window. See if ' it has the target instance handle. test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid) If test_pid = target_pid Then ' This is the target. InstanceToWnd = test_hwnd Exit Do End If End If ' Examine the next window. test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT) Loop End Function
得到窗口handle可以用FindWindow===========================================================
我要学好C++啊 \(-o-)/
===========================================================
'API
EnumProcessModules
就将分数发下去!
greater than 32 if successful, or an error value that is less than or equal to 32 otherwise.
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Sub EndFun()
On Error GoTo ErrTrap
Dim hwnd As Long
Dim i As Long
Dim WinNm As String
WinNm = "about:blank - Microsoft Internet Explorer"
hwnd = FindWindow(vbNullString, WinNm)
If hwnd <> 0 Then i = PostMessage(hwnd, WM_CLOSE, 0, 0)
GoTo WayOut
ErrTrap:
WayOut:
End SubPrivate Sub Form_Load()
EndFun
End Sub
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wcmd As Long) As LongPrivate Function InstanceToWnd(ByVal target_pid As Long) As Long
Dim test_hwnd As Long
Dim test_pid As Long
Dim test_thread_id As Long
' Get the first window handle.
test_hwnd = FindWindowLong(ByVal 0&, ByVal 0&) ' Loop until we find the target or we run out
' of windows.
Do While test_hwnd <> 0
' See if this window has a parent. If not,
' it is a top-level window.
If GetParent(test_hwnd) = 0 Then
' This is a top-level window. See if
' it has the target instance handle.
test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid) If test_pid = target_pid Then
' This is the target.
InstanceToWnd = test_hwnd
Exit Do
End If
End If
' Examine the next window.
test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
Loop
End Function