Option Explicit
Private Declare Function GetDesktopWindow()Function GetDesktopWindow
Lib "user32" () As Long
Private Declare Function GetWindow()Function GetWindow Lib "user32"
(ByVal hwnd As Long, ByVal wCmd As
Long) As Long
Private Declare Function GetWindowText()Function GetWindowText Lib
"user32" Alias "GetWindowTextA" (ByVal hwnd
As Long, _
ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function SetWindowPos()Function SetWindowPos Lib
"user32" (ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long,
ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const HWND_TOPMOST = -1
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Sub Form_Load()Sub Form_Load()
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or
SWP_NOSIZE
Dim lngDeskTopHandle As Long
Dim lngHand As Long
Dim strName As String * 255
Dim lngWindowCount As Long
lngDeskTopHandle = GetDesktopWindow()
lngHand = GetWindow(lngDeskTopHandle, GW_CHILD)
lngWindowCount = 1
Do While lngHand <> 0
GetWindowText lngHand, strName, Len(strName)
lngHand = GetWindow(lngHand, GW_HWNDNEXT)
If Left$(strName, 1) <> vbNullChar Then
Me.list1.AddItem Left$(strName, InStr(1, strName, vbNullChar))
lngWindowCount = lngWindowCount + 1
End If
Loop
Label1.Caption = "程序列表中共有:" & lngWindowCount & "個運行程序 "
End Sub
Private Sub Command1_Click()Sub Command1_Click()
End
End Sub