获取当前Windows所有进程

0 Reply , Posted in 程序代码 on 2017 28, 2017

//////////////////////////model.bas

Option Explicit
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwprocessid As Long) As Long
Const MAXLEN = 255
Public Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Boolean
 If GetCaptionFromHwnd(hWnd) <> "" Then Form1.List1.AddItem Str$(hWnd) & " " & CStr(ProcIDFromWnd(hWnd)) & " " & GetCaptionFromHwnd(hWnd)
 EnumWindowsProc = True
End Function

Public Function ProcIDFromWnd(ByVal hWnd As Long) As Long
 Dim idProc As Long
 GetWindowThreadProcessId hWnd, idProc
 ProcIDFromWnd = idProc
End Function

Public Function GetCaptionFromHwnd(hWnd As Long) As String
 Dim strBuffer$, intCount%
 strBuffer = String$(MAXLEN - 1, 0)
 intCount = GetWindowText(hWnd, strBuffer, MAXLEN)
 If intCount > 0 Then GetCaptionFromHwnd = Left$(strBuffer, intCount)
End Function

///////////////////////////////form1.frm////////////////////

Private Sub Command1_Click()
 List1.Clear
 EnumWindows AddressOf EnumWindowsProc, ByVal 0&
End Sub

发表评论:



◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

                       

  鄂公网安备 42112502000156号     鄂ICP备16019550号