程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> Visual Basic語言 >> VB綜合教程 >> VB取得所有進程

VB取得所有進程

編輯:VB綜合教程
 

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
 

 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved