今天我們共同來看一下,,如何用VB編程來查看當前計算機系統(tǒng)正在運行的程序共有多少,。 '變量定義,,dll引用部分 Option Explicit Private Declare Function GetDesktopWindow Lib 'user32' () As Long Private Declare Function GetWindow Lib 'user32' (ByVal hwnd As Long, ByVal wCmd As Long) As Long Private Declare Function GetWindowText Lib 'user32' Alias 'GetWindowTextA' (ByVal hwnd As Long, _ ByVal lpString As String, ByVal cch As Long) As Long Private Declare 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 '窗體載入時執(zhí)行過程 Private Sub Form_Load() 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 跟我學VB 1,、VB從零基礎(chǔ)入門到精通的全套視頻學習資料,,包括親自講解的從入門到精通視頻,、課件教程,、編程實例大全(包含源代碼工程文件)、學習總結(jié)資料等優(yōu)惠發(fā)放,; 2,、VB與數(shù)據(jù)庫開發(fā)、VB網(wǎng)絡(luò)通信,、多媒體開發(fā)等高級應(yīng)用教程優(yōu)惠發(fā)放,。 |
|