vb 任务管理器 应用程序列表

怎么做类似windows任务管理器的应用程序列表用EnumWindows、GetWindowText获得的窗体名太多了,我要的是像任务管理器中的那种列表看来是我没说清楚呀... 怎么做类似windows任务管理器的应用程序列表

用EnumWindows、GetWindowText获得的窗体名太多了,我要的是像任务管理器中的那种列表
看来是我没说清楚呀 两位说的都是进程列表
我想要的是应用程序列表,打开任务管理器有个"应用程序"选项卡,我要的就是那个列表
展开
 我来答
dl_会飞的青蛙
2009-01-04 · TA获得超过2456个赞
知道大有可为答主
回答量:3294
采纳率:0%
帮助的人:3354万
展开全部
有的控件要自己添加一下
:)
Option Explicit

Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Const MAX_PATH As Integer = 260
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type
Const TH32CS_SNAPheaplist = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPthread = &H4
Const TH32CS_SNAPmodule = &H8
Const TH32CS_SNAPall = TH32CS_SNAPPROCESS + TH32CS_SNAPheaplist + TH32CS_SNAPthread + TH32CS_SNAPmodule

Private Sub Command1_Click()
Dim i As Long, lPid As Long
Dim Proc As PROCESSENTRY32
Dim hSnapShot As Long
ListView1.ListItems.Clear '清空ListView
hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPall, 0) '获得进程“快照”的句柄
Proc.dwSize = Len(Proc)
lPid = ProcessFirst(hSnapShot, Proc) '获取第一个进程的PROCESSENTRY32结构信息数据
i = 0
Do While lPid <> 0 '当返回值非零时继续获取下一个进程
ListView1.ListItems.Add , "a" & i, Hex(Proc.th32ProcessID) '将进程ID添加到ListView1第一列
ListView1.ListItems("a" & i).SubItems(1) = Proc.szExeFile '将进程名添加到ListView1第二列
i = i + 1
lPid = ProcessNext(hSnapShot, Proc) '循环获取下一个进程的PROCESSENTRY32结构信息数据
Loop
CloseHandle hSnapShot '关闭进程“快照”句柄
End Sub

Private Sub Command2_Click()
Dim lPHand As Long, TMBack As Long
If ListView1.SelectedItem.Text <> "" Then
If MsgBox("确实要结束进程[" & ListView1.SelectedItem.SubItems(1) & "]吗?", vbYesNo) = vbYes Then
lPHand = Val("&H" & ListView1.SelectedItem.Text)
lPHand = OpenProcess(1&, True, lPHand) '获取进程句柄
TMBack = TerminateProcess(lPHand, 0&) '关闭进程
If TMBack <> 0 Then
MsgBox ListView1.SelectedItem.SubItems(1) & "已经被终止!"
Else
MsgBox ListView1.SelectedItem.SubItems(1) & "不能被终止!"
End If
CloseHandle lPHand
Command1_Click '刷新进程列表
End If
End If
End Sub

Private Sub form_Load()
Me.Caption = "进程管理器"
Command1.Caption = "刷新"
Command2.Caption = "结束进程"
ListView1.ColumnHeaders.Clear
ListView1.ColumnHeaders.Add , "a", "进程ID", 600
ListView1.ColumnHeaders.Add , "b", "进程名", 4000
ListView1.View = lvwReport
Command1_Click '刷新进程列表
End Sub

参考资料: vb吧

深圳云诺科技
2024-11-11 广告
敏捷项目管理平台是源自于企鹅厂的敏捷研发协作平台,提供贯穿敏捷研发生命周期的一站式服务。覆盖从产品概念形成、产品规划、需求分析、项目规划和跟踪、质量测试到构建发布、用户反馈跟踪的产品研发全生命周期,提供了灵活的可定制化应用和强大的集成能力,... 点击进入详情页
本回答由深圳云诺科技提供
mosquitokobe
2009-01-05 · TA获得超过4253个赞
知道大有可为答主
回答量:5008
采纳率:50%
帮助的人:0
展开全部
'模块
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
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
lijinfeng042
2009-01-04 · TA获得超过678个赞
知道小有建树答主
回答量:725
采纳率:0%
帮助的人:590万
展开全部
'给你个简单方便的程序?
'创建如下控件:
'Command1,Text1,Timer1.
'设置Text1.MultiLine = True?(一定!)
'单击按钮,稍候片刻,在Text2中显示结果。
'===========================
Const p = "d:\a.txt"
Private Sub Command1_Click()
Timer1.Enabled = True
Timer1.Interval = 1000
Text1.Text = ""
Dim t As String
Shell "cmd /c echo. >""d:\a.txt""" '创建空文件
Shell "cmd /c" & "tasklist" & ">" & p '读取任务
End Sub

Private Sub Form_Load()
Timer1.Enabled = False

End Sub

Private Sub Timer1_Timer() '读取文件
Open p For Input As #1
Do While EOF(1) = False
Line Input #1, t
Text1.Text = Text1.Text + t
Loop
Close #1
Timer1.Enabled = False
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式