www.pudn.com > MFCtest.rar > MFCtestDlg.cpp
// MFCtestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MFCtest.h"
#include "MFCtestDlg.h"
#include "Pdh.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMFCtestDlg dialog
CMFCtestDlg::CMFCtestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMFCtestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMFCtestDlg)
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMFCtestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMFCtestDlg)
DDX_Control(pDX, IDC_LIST1, m_LIST);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMFCtestDlg, CDialog)
//{{AFX_MSG_MAP(CMFCtestDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMFCtestDlg message handlers
BOOL CMFCtestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
LV_COLUMN lvC;
TCHAR szString[10][20] = {_T("进程名"), _T("PID"), _T("父进程PID"), _T("运行时间"), _T("线程数"), _T("用户时间") , _T("句柄数"), _T("基本优先级"), _T("内存")};
m_LIST.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvC.fmt = LVCFMT_LEFT;
lvC.cx = 75;
for(int i = 0; i < 9; i++)
{
lvC.iSubItem=i;
lvC.pszText = szString[i];
m_LIST.InsertColumn(i,&lvC);
}
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CMFCtestDlg::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();
}
}
HCURSOR CMFCtestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMFCtestDlg::OnOK()
{
// TODO: Add extra validation here
int i;
LV_ITEM lvI;
CPDH *aCPDH=new CPDH();
aCPDH->getProcessInfo();
lvI.mask = LVIF_TEXT | LVIF_STATE;
lvI.state = 0;
lvI.stateMask = 0;
aCPDH->goFirstProcess();
ProcessInfo *temp;
temp=aCPDH->currentProcess();
m_LIST.DeleteAllItems();
for (i = 0; i < aCPDH->processNum(); i++)
{
lvI.iItem = i;
lvI.iSubItem = 0;
lvI.pszText = temp->PRONAME;
m_LIST.InsertItem(&lvI);
for(int j=1;j<9;j++)
{
lvI.pszText=temp->info[j];
lvI.iSubItem = j;
m_LIST.SetItem(&lvI);
//CWnd::MessageBox(temp->info[j],"",0);
}
aCPDH->goNextProcess();
temp=aCPDH->currentProcess();
}
UpdateData(false);
//CDialog::OnOK();
}