-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyThreadDlg.cpp
More file actions
157 lines (117 loc) · 3.73 KB
/
Copy pathMyThreadDlg.cpp
File metadata and controls
157 lines (117 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// MyThreadDlg.cpp : 实现文件
//
#include "pch.h"
#include "MyThreadDlg.h"
#include "afxdialogex.h"
#include "MyHead.h"
#include <afx.h>
#include <afxdd_.h>
#include <afxmsg_.h>
#include <afxres.h>
#include <afxstr.h>
#include <afxwin.h>
#include "ClistCtrlEx.h"
#include <minwindef.h>
#include <windef.h>
#include <tchar.h>
#include <CommCtrl.h>
#include <winnt.h>
#include <WinUser.h>
#include "resource.h"
extern DWORD g_Pid;
// CMyThreadDlg 对话框
IMPLEMENT_DYNAMIC(MyThreadDlg, CDialogEx)
MyThreadDlg::MyThreadDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(IDD_MYTHREAD_DIALOG, pParent)
{
}
MyThreadDlg::~MyThreadDlg()
{
}
void MyThreadDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST_THREAD, m_List_Thread);
}
BEGIN_MESSAGE_MAP(MyThreadDlg, CDialogEx)
ON_COMMAND(ID_SUSPENDTHREAD, &MyThreadDlg::OnSuspendthread)
ON_COMMAND(ID_RESUMETHREAD, &MyThreadDlg::OnResumethread)
ON_COMMAND(ID_TERMINATETHREAD, &MyThreadDlg::OnTerminatethread)
ON_NOTIFY(NM_RCLICK, IDC_LIST_THREAD, &MyThreadDlg::OnRclickListThread)
ON_NOTIFY(NM_CLICK, IDC_LIST_THREAD, &MyThreadDlg::OnClickListThread)
END_MESSAGE_MAP()
// CMyThreadDlg 消息处理程序
void PrintThreadList(ClistCtrlEx &m_List_Thread, THREADLIST &nThreadList, DWORD nThreadNum)
{
m_List_Thread.DeleteAllItems();
for (DWORD i = 0; i < nThreadNum; i++)
{
DWORD nIndex = m_List_Thread.GetItemCount();
m_List_Thread.InsertItem(nIndex, nThreadList.th32ThreadID[nIndex] );
m_List_Thread.SetItemText(nIndex, 1, nThreadList.szExePath[nIndex]);
m_List_Thread.SetItemText(nIndex, 2, nThreadList.th32OwnerProcessID[nIndex]);
m_List_Thread.SetItemText(nIndex, 3, nThreadList.tpBasePri[nIndex]);
m_List_Thread.SetItemText(nIndex, 4, nThreadList.szThreadState[nIndex]);
}
}
BOOL MyThreadDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
m_Menu.LoadMenu(IDR_MENU2);
SetMenu(&m_Menu);
m_List_Thread.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
m_List_Thread.InsertColumn(0, TEXT("线程ID"), 0, 180);
m_List_Thread.InsertColumn(1, TEXT("进程名"), 0, 200);
m_List_Thread.InsertColumn(2, TEXT("进程ID"), 0, 100);
m_List_Thread.InsertColumn(3, TEXT("优先级"), 0, 100);
m_List_Thread.InsertColumn(4, TEXT("线优状态"), 0, 100);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
THREADLIST nThreadList = {};
DWORD nNum = EnumThreadList(nThreadList, g_Pid);//枚举进程列表
PrintThreadList(m_List_Thread, nThreadList, nNum);//打印进程到列表
ClearThreadList(nThreadList);
return TRUE;
}
void MyThreadDlg::OnSuspendthread()
{
DWORD nNow = m_List_Thread.GetSelectionMark();
CString szPid = m_List_Thread.GetItemText(nNow, 0);
DWORD nPid;
_stscanf_s(szPid, TEXT("%d"), &nPid);
SetThreadState(nPid, TRUE);
}
void MyThreadDlg::OnResumethread()
{
DWORD nNow = m_List_Thread.GetSelectionMark();
CString szPid = m_List_Thread.GetItemText(nNow, 0);
DWORD nPid;
_stscanf_s(szPid, TEXT("%d"), &nPid);
SetThreadState(nPid,FALSE);
}
void MyThreadDlg::OnTerminatethread()
{
DWORD nNow = m_List_Thread.GetSelectionMark();
CString szPid = m_List_Thread.GetItemText(nNow, 0);
DWORD nPid;
_stscanf_s(szPid, TEXT("%d"), &nPid);
EndThread(nPid);
}
void MyThreadDlg::OnClickListThread(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
*pResult = 0;
}
void MyThreadDlg::OnRclickListThread(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
*pResult = 0;
if (m_List_Thread.GetSelectionMark() != -1)
{
CMenu *nMenu = m_Menu.GetSubMenu(0);
POINT pos;
GetCursorPos(&pos);
nMenu->TrackPopupMenu(TPM_LEFTALIGN, pos.x, pos.y, this);
}
}