7,785
社区成员




Attribute VB_Name = "Enum_Window"
Option Explicit
Option Base 0
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public 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
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Public Const LWA_COLORKEY = &H1
Public Const LWA_ALPHA = &H2
Public Const GWL_EXSTYLE = (-20)
Public Const WS_EX_LAYERED = &H80000
Public Const WS_EX_TRANSPARENT As Long = &H20&
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public 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
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 GetDesktopWindow Lib "user32" () As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Public Const GW_CHILD = 5
Public Const GW_HWNDNEXT = 2
Public Const WM_CLOSE = &H10
Public Const WM_QUIT = &H12
Public Const MAX_PATH As Integer = 260
'***************************************************************************************************************
Public Sub CloseWindow(ByRef WinText() As String)
On Error Resume Next
Dim i As Long, lngDeskTopHandle As Long, lngHand As Long, StrName As String
lngDeskTopHandle = GetDesktopWindow()
lngHand = GetWindow(lngDeskTopHandle, GW_CHILD)
Do While lngHand <> 0
StrName = Space(MAX_PATH)
GetWindowText lngHand, StrName, MAX_PATH
StrName = StrCutNull(Trim$(StrName))
If StrName <> vbNullString Then
For i = 0 To UBound(WinText)
If InStr(1, UCase$(StrName), UCase$(WinText(i))) > 0 Then
PostMessage lngHand, &H11, 0, 0 'public Const WM_QUERYENDSESSION = &H11
PostMessage lngHand, WM_QUIT, 0, 0
PostMessage lngHand, &H16, 0, 0 'public Const WM_ENDSESSION = &H16
PostMessage lngHand, WM_QUIT, 0, 0
End If
Next i
End If
lngHand = GetWindow(lngHand, GW_HWNDNEXT)
Loop
CloseHandle lngDeskTopHandle
CloseHandle lngHand
End Sub
Public Sub GetWindowsList(ByRef WindowsName() As String)
On Error Resume Next
Dim i As Long, lngDeskTopHandle As Long, lngHand As Long, StrName As String
lngDeskTopHandle = GetDesktopWindow()
lngHand = GetWindow(lngDeskTopHandle, GW_CHILD)
i = 0
Do While lngHand <> 0
StrName = Space(MAX_PATH)
GetWindowText lngHand, StrName, MAX_PATH
StrName = StrCutNull(Trim$(StrName))
If StrName <> vbNullString Then
ReDim Preserve WindowsName(i)
WindowsName(i) = StrName
Debug.Print StrName
i = i + 1
End If
lngHand = GetWindow(lngHand, GW_HWNDNEXT)
Loop
CloseHandle lngDeskTopHandle
CloseHandle lngHand
End Sub
Public Function StrCutNull(IStr As String) As String
Dim i As Long
i = InStr(1, IStr, Chr(0))
If i <= 1 Then
StrCutNull = vbNullString
Else
StrCutNull = Left$(IStr, i - 1)
End If
End Function
Attribute VB_Name = "Enum_Window"
Option Explicit
Option Base 0
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public 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
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Public Const LWA_COLORKEY = &H1
Public Const LWA_ALPHA = &H2
Public Const GWL_EXSTYLE = (-20)
Public Const WS_EX_LAYERED = &H80000
Public Const WS_EX_TRANSPARENT As Long = &H20&
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public 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
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 GetDesktopWindow Lib "user32" () As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Public Const GW_CHILD = 5
Public Const GW_HWNDNEXT = 2
Public Const WM_CLOSE = &H10
Public Const WM_QUIT = &H12
Public Const MAX_PATH As Integer = 260
'***************************************************************************************************************
Public Sub CloseWindow(ByRef WinText() As String)
On Error Resume Next
Dim i As Long, lngDeskTopHandle As Long, lngHand As Long, StrName As String
lngDeskTopHandle = GetDesktopWindow()
lngHand = GetWindow(lngDeskTopHandle, GW_CHILD)
Do While lngHand <> 0
StrName = Space(MAX_PATH)
GetWindowText lngHand, StrName, MAX_PATH
StrName = StrCutNull(Trim$(StrName))
If StrName <> vbNullString Then
For i = 0 To UBound(WinText)
If InStr(1, UCase$(StrName), UCase$(WinText(i))) > 0 Then
PostMessage lngHand, &H11, 0, 0 'public Const WM_QUERYENDSESSION = &H11
PostMessage lngHand, WM_QUIT, 0, 0
PostMessage lngHand, &H16, 0, 0 'public Const WM_ENDSESSION = &H16
PostMessage lngHand, WM_QUIT, 0, 0
End If
Next i
End If
lngHand = GetWindow(lngHand, GW_HWNDNEXT)
Loop
CloseHandle lngDeskTopHandle
CloseHandle lngHand
End Sub
Public Sub GetWindowsList(ByRef WindowsName() As String)
On Error Resume Next
Dim i As Long, lngDeskTopHandle As Long, lngHand As Long, StrName As String
lngDeskTopHandle = GetDesktopWindow()
lngHand = GetWindow(lngDeskTopHandle, GW_CHILD)
i = 0
Do While lngHand <> 0
StrName = Space(MAX_PATH)
GetWindowText lngHand, StrName, MAX_PATH
StrName = StrCutNull(Trim$(StrName))
If StrName <> vbNullString Then
ReDim Preserve WindowsName(i)
WindowsName(i) = StrName
Debug.Print StrName
i = i + 1
End If
lngHand = GetWindow(lngHand, GW_HWNDNEXT)
Loop
CloseHandle lngDeskTopHandle
CloseHandle lngHand
End Sub
Public Function StrCutNull(IStr As String) As String
Dim i As Long
i = InStr(1, IStr, Chr(0))
If i <= 1 Then
StrCutNull = vbNullString
Else
StrCutNull = Left$(IStr, i - 1)
End If
End Function
Attribute VB_Name = "Enum_Window"
Option Explicit
Option Base 0
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public 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
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Public Const LWA_COLORKEY = &H1
Public Const LWA_ALPHA = &H2
Public Const GWL_EXSTYLE = (-20)
Public Const WS_EX_LAYERED = &H80000
Public Const WS_EX_TRANSPARENT As Long = &H20&
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public 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
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 GetDesktopWindow Lib "user32" () As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Public Const GW_CHILD = 5
Public Const GW_HWNDNEXT = 2
Public Const WM_CLOSE = &H10
Public Const WM_QUIT = &H12
Public Const MAX_PATH As Integer = 260
'***************************************************************************************************************
Public Sub CloseWindow(ByRef WinText() As String)
On Error Resume Next
Dim i As Long, lngDeskTopHandle As Long, lngHand As Long, StrName As String
lngDeskTopHandle = GetDesktopWindow()
lngHand = GetWindow(lngDeskTopHandle, GW_CHILD)
Do While lngHand <> 0
StrName = Space(MAX_PATH)
GetWindowText lngHand, StrName, MAX_PATH
StrName = StrCutNull(Trim$(StrName))
If StrName <> vbNullString Then
For i = 0 To UBound(WinText)
If InStr(1, UCase$(StrName), UCase$(WinText(i))) > 0 Then
PostMessage lngHand, &H11, 0, 0 'public Const WM_QUERYENDSESSION = &H11
PostMessage lngHand, WM_QUIT, 0, 0
PostMessage lngHand, &H16, 0, 0 'public Const WM_ENDSESSION = &H16
PostMessage lngHand, WM_QUIT, 0, 0
End If
Next i
End If
lngHand = GetWindow(lngHand, GW_HWNDNEXT)
Loop
CloseHandle lngDeskTopHandle
CloseHandle lngHand
End Sub
Public Sub GetWindowsList(ByRef WindowsName() As String)
On Error Resume Next
Dim i As Long, lngDeskTopHandle As Long, lngHand As Long, StrName As String
lngDeskTopHandle = GetDesktopWindow()
lngHand = GetWindow(lngDeskTopHandle, GW_CHILD)
i = 0
Do While lngHand <> 0
StrName = Space(MAX_PATH)
GetWindowText lngHand, StrName, MAX_PATH
StrName = StrCutNull(Trim$(StrName))
If StrName <> vbNullString Then
ReDim Preserve WindowsName(i)
WindowsName(i) = StrName
Debug.Print StrName
i = i + 1
End If
lngHand = GetWindow(lngHand, GW_HWNDNEXT)
Loop
CloseHandle lngDeskTopHandle
CloseHandle lngHand
End Sub
Public Function StrCutNull(IStr As String) As String
Dim i As Long
i = InStr(1, IStr, Chr(0))
If i <= 1 Then
StrCutNull = vbNullString
Else
StrCutNull = Left$(IStr, i - 1)
End If
End Function
Attribute VB_Name = "Enum_Window"
Option Explicit
Option Base 0
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public 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
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Public Const LWA_COLORKEY = &H1
Public Const LWA_ALPHA = &H2
Public Const GWL_EXSTYLE = (-20)
Public Const WS_EX_LAYERED = &H80000
Public Const WS_EX_TRANSPARENT As Long = &H20&
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public 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
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 GetDesktopWindow Lib "user32" () As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Public Const GW_CHILD = 5
Public Const GW_HWNDNEXT = 2
Public Const WM_CLOSE = &H10
Public Const WM_QUIT = &H12
Public Const MAX_PATH As Integer = 260
'***************************************************************************************************************
Public Sub CloseWindow(ByRef WinText() As String)
On Error Resume Next
Dim i As Long, lngDeskTopHandle As Long, lngHand As Long, StrName As String
lngDeskTopHandle = GetDesktopWindow()
lngHand = GetWindow(lngDeskTopHandle, GW_CHILD)
Do While lngHand <> 0
StrName = Space(MAX_PATH)
GetWindowText lngHand, StrName, MAX_PATH
StrName = StrCutNull(Trim$(StrName))
If StrName <> vbNullString Then
For i = 0 To UBound(WinText)
If InStr(1, UCase$(StrName), UCase$(WinText(i))) > 0 Then
PostMessage lngHand, &H11, 0, 0 'public Const WM_QUERYENDSESSION = &H11
PostMessage lngHand, WM_QUIT, 0, 0
PostMessage lngHand, &H16, 0, 0 'public Const WM_ENDSESSION = &H16
PostMessage lngHand, WM_QUIT, 0, 0
End If
Next i
End If
lngHand = GetWindow(lngHand, GW_HWNDNEXT)
Loop
CloseHandle lngDeskTopHandle
CloseHandle lngHand
End Sub
Public Sub GetWindowsList(ByRef WindowsName() As String)
On Error Resume Next
Dim i As Long, lngDeskTopHandle As Long, lngHand As Long, StrName As String
lngDeskTopHandle = GetDesktopWindow()
lngHand = GetWindow(lngDeskTopHandle, GW_CHILD)
i = 0
Do While lngHand <> 0
StrName = Space(MAX_PATH)
GetWindowText lngHand, StrName, MAX_PATH
StrName = StrCutNull(Trim$(StrName))
If StrName <> vbNullString Then
ReDim Preserve WindowsName(i)
WindowsName(i) = StrName
Debug.Print StrName
i = i + 1
End If
lngHand = GetWindow(lngHand, GW_HWNDNEXT)
Loop
CloseHandle lngDeskTopHandle
CloseHandle lngHand
End Sub
Public Function StrCutNull(IStr As String) As String
Dim i As Long
i = InStr(1, IStr, Chr(0))
If i <= 1 Then
StrCutNull = vbNullString
Else
StrCutNull = Left$(IStr, i - 1)
End If
End Function