CSDN博客

img yinweihong

列举正在运行的所有应用程序

发表于2004/9/27 1:45:00  1383人阅读

Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex 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 SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Const SW_SHOW = 5
Public Const SW_RESTORE = 9
Public Const GW_OWNER = 4
Public Const GWL_HWNDPARENT = (-8)
Public Const GWL_EXSTYLE = (-20)
Public Const WS_EX_TOOLWINDOW = &H80
Public Const WS_EX_APPWINDOW = &H40000
Public Const LB_ADDSTRING = &H180
Public Const LB_SETITEMDATA = &H19A
Public Const EWX_FORCE = 4
Public Const EWX_LOGOFF = 0
Public Const EWX_REBOOT = 2
Public Const EWX_SHUTDOWN = 1
Const MAX_PATH& = 260
Private Const SW_HIDE = 0
Private Const WM_CLOSE = &H10
Public HHWnd As Long

Public Function WhichWindowsCallBack(ByVal hwnd As Long, ByVal lParam As Long) As Long
    Dim lReturn     As Long
    Dim lExStyle    As Long
    Dim bNoOwner    As Boolean
    Dim sWindowText As String

    If hwnd <> Form1.hwnd Then
        If IsWindowVisible(hwnd) Then
            If GetParent(hwnd) = 0 Then
                bNoOwner = (GetWindow(hwnd, GW_OWNER) = 0)
                lExStyle = GetWindowLong(hwnd, GWL_EXSTYLE)

                If (((lExStyle And WS_EX_TOOLWINDOW) = 0) And bNoOwner) Or _
                   ((lExStyle And WS_EX_APPWINDOW) And Not bNoOwner) Then

                    sWindowText = Space$(256)
                    lReturn = GetWindowText(hwnd, sWindowText, Len(sWindowText))
                    If lReturn Then

                        sWindowText = Left$(sWindowText, lReturn)
                        lReturn = SendMessage(lParam, LB_ADDSTRING, 0, ByVal sWindowText)
                        Call SendMessage(lParam, LB_SETITEMDATA, lReturn, ByVal hwnd)
                    End If
                End If
            End If
        End If
    End If
    HHWnd = hwnd
    WhichWindowsCallBack = True
End Function

Public Function fEnumWindows(lst As ListBox) As Long
    With lst
        .Clear
        Call EnumWindows(AddressOf WhichWindowsCallBack, .hwnd)
        fEnumWindows = .ListCount
    End With
End Function
Private Sub Form_Load()
    Call fEnumWindows(List1)
End Sub

阅读全文
0 0

相关文章推荐

img
取 消
img