?? listprocessdlg.cpp
字號:
// listprocessDlg.cpp : implementation file
//
#include "stdafx.h"
#include "listprocess.h"
#include "listprocessDlg.h"
#include <tlhelp32.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CListprocessDlg dialog
CListprocessDlg::CListprocessDlg(CWnd* pParent /*=NULL*/)
: CDialog(CListprocessDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CListprocessDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CListprocessDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CListprocessDlg)
DDX_Control(pDX, IDC_LIST2, m_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CListprocessDlg, CDialog)
//{{AFX_MSG_MAP(CListprocessDlg)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CListprocessDlg message handlers
BOOL CListprocessDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CListprocessDlg::OnButton1()
{
m_list.DeleteAllItems();
while (m_list.DeleteColumn(0));
m_list.ModifyStyle(0, LVS_REPORT);
m_list.SetExtendedStyle(LVS_SHOWSELALWAYS | LVS_EX_FULLROWSELECT);
m_list.InsertColumn(0, L"序號", LVCFMT_LEFT, 30);
m_list.InsertColumn(1, L"進程ID", LVCFMT_LEFT, 60);
m_list.InsertColumn(2, L"進程名稱", LVCFMT_LEFT, 120);
m_list.InsertColumn(3, L"父進程ID", LVCFMT_LEFT, 60);
HANDLE handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 info;
info.dwSize = sizeof(PROCESSENTRY32);
int i = 0;
if (Process32First(handle, &info))
{
if (GetLastError() == ERROR_NO_MORE_FILES)
{
AfxMessageBox(L"No More Process");
}
else
{
CString id;
id.Format(L"%d", i);
m_list.InsertItem(i, id);
id.Format(L"%x", info.th32ProcessID);
m_list.SetItemText(i, 1, id);
m_list.SetItemData(i, info.th32ProcessID);
id.Format(L"%s", info.szExeFile);
m_list.SetItemText(i, 2, id);
id.Format(L"%x", info.th32ParentProcessID);
m_list.SetItemText(i, 3, id);
i++;
while (Process32Next(handle,&info) != FALSE)
{
id.Format(L"%d", i);
m_list.InsertItem(i, id);
id.Format(L"%x", info.th32ProcessID);
m_list.SetItemText(i, 1, id);
m_list.SetItemData(i,info.th32ProcessID);
id.Format(L"%s",info.szExeFile);
m_list.SetItemText(i, 2, id);
id.Format(L"%x", info.th32ParentProcessID);
m_list.SetItemText(i, 3, id);
i++;
}
}
}
CloseHandle(handle);
}
void CListprocessDlg::OnButton2()
{
int i = m_list.GetSelectionMark();
HANDLE h = OpenProcess( 0,
FALSE,
m_list.GetItemData(i)
);
ASSERT( h != NULL);
if (h)
{
MessageBeep(MB_OK);
TerminateProcess(h, 0);
}
CloseHandle(h);
m_list.DeleteItem(i);
//OnOK(); // TODO: Add your control notification handler code here
}
void CListprocessDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
//SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -