#include "stdafx.h"
#include "进程管理器.h"
#include "进程管理器Dlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog
{
public:
CAboutDlg();// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA // ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialogCMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDlg)
// 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 CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
DDX_Control(pDX, IDC_LIST2, m_1);
//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_NOTIFY(NM_DBLCLK, IDC_LIST2, OnDblclkList2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlersBOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
} // 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
// TODO: Add extra initialization here
m_1.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES );
CRect rect;
PROCESSENTRY32 p32;
HICON hicon[200];
char name[MAX_PATH];
imag.Create(32,32,ILC_COLOR16,1,1);
HANDLE handle1;SHFILEINFO sh;
CString s;DWORD pd[1024],pt;int count;
m_1.GetClientRect(rect);
m_1.InsertColumn(0,"进程名",LVCFMT_LEFT,2*rect.Width()/6);
m_1.InsertColumn(1,"进程名ID",LVCFMT_LEFT,rect.Width()/6);
m_1.InsertColumn(2,"进程名路径",LVCFMT_LEFT,3*rect.Width()/6);
HANDLE handle=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
Process32First(handle,&p32);
EnumProcesses(pd,sizeof(pd),&pt);
count=pt/sizeof(DWORD);
for(int i=0;i<count;i++)
{ handle1=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,FALSE,pd[i]); GetModuleFileNameEx(handle1,NULL,name,sizeof(name));
SHGetFileInfo(name,FILE_ATTRIBUTE_NORMAL,&sh,sizeof(sh),SHGFI_ICON );
hicon[i]=CopyIcon(sh.hIcon);
imag.Add(hicon[i]);
m_1.SetImageList(&imag,LVSIL_SMALL);
s.Format("%lu",p32.th32ProcessID);
m_1.InsertItem(i,p32.szExeFile,i-2);
m_1.SetItemText(i,1,s);
m_1.SetItemText(i,2,name);
Process32Next(handle,&p32);
}
CloseHandle(handle);
CloseHandle(handle1);
return TRUE; // return TRUE unless you set the focus to a control
}void CMyDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.void CMyDlg::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();
}
}// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}void CMyDlg::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}void CMyDlg::OnDblclkList2(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
NMLISTVIEW* pp=(NMLISTVIEW*)pNMHDR;
char pr[200];CString s1;
m_1.GetItemText(pp->iItem,1,pr,200);
s1=m_1.GetItemText(pp->iItem,0);
if(IDYES!=MessageBox("是否结束进程",s1,MB_YESNO))
return ;
int t;
t=atoi(pr);
HANDLE handle3;
handle3=OpenProcess(PROCESS_ALL_ACCESS,FALSE,t);
::TerminateProcess(handle3,0);
m_1.DeleteItem(pp->iItem);
CloseHandle(handle3);
*pResult = 0;
}
解决方案 »
- 急问用C++、SCPI语言和GPIB总线开发仪器程控软件的问题!!!
- vc++开发usb通信问题
- 请问谁能用通俗的文字语言说明一下Gabor小波变换的原理啊,谢谢!
- 一个制作透明窗体的问题(30分)
- 帮忙找篇C++在网络编程方面的英文技术文章
- 超难!!!再次提问ATL事件向外界(VB)传递safearray参数问题。
- 有符号十六进制"0xFFEA"如何快速计算得到"-22",是否有相关函数?
- 请问初学用vc的ado对sql server数据库编程看什么书
- 一个本科女生真的很无力。。简而言之就是怎样用一个程序的输出控制另外一个MFC程序?
- 这里没有高手吗?请高手现身帮忙解答困扰多时的问题-关于硬件厂家提供API函数问题
- MFC快速开发界面的简单疑问?????
- 怎么在mfc中弹出对话框
哦,一直以为不支持中文呢