📄 systeminfodlg.cpp
字号:
// SystemInfoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SystemInfo.h"
#include "SystemInfoDlg.h"
#include <atlbase.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class 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()
/////////////////////////////////////////////////////////////////////////////
// CSystemInfoDlg dialog
CSystemInfoDlg::CSystemInfoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSystemInfoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSystemInfoDlg)
// 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 CSystemInfoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSystemInfoDlg)
DDX_Control(pDX, IDC_DRIVERLIST, m_driverlist);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSystemInfoDlg, CDialog)
//{{AFX_MSG_MAP(CSystemInfoDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_GETSYSTEMINFO, OnGetsysteminfo)
ON_BN_CLICKED(IDC_AUTORENOVATE, OnAutorenovate)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_SETTOP, OnSettop)
ON_BN_CLICKED(IDC_USEGBTYPE, OnUsegbtype)
ON_BN_CLICKED(IDC_SAVE, OnSave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSystemInfoDlg message handlers
BOOL CSystemInfoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
InitDriverList();
OnGetsysteminfo();
// 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
return TRUE; // return TRUE unless you set the focus to a control
}
BOOL CSystemInfoDlg::InitDriverList()
{
for(int n=0;n<10;n++)
{
m_driverlist.DeleteColumn(0);
}
m_driverlist.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
m_driverlist.InsertColumn(0,"驱动器",LVCFMT_LEFT,50);
if(IsDlgButtonChecked(IDC_USEGBTYPE))
{
m_driverlist.InsertColumn(1,"大小GB",LVCFMT_LEFT,75);
m_driverlist.InsertColumn(2,"已用GB",LVCFMT_LEFT,75);
m_driverlist.InsertColumn(3,"可用GB",LVCFMT_LEFT,75);
}
else
{
m_driverlist.InsertColumn(1,"大小MB",LVCFMT_LEFT,75);
m_driverlist.InsertColumn(2,"已用MB",LVCFMT_LEFT,75);
m_driverlist.InsertColumn(3,"可用MB",LVCFMT_LEFT,75);
}
m_driverlist.InsertColumn(4,"占用(%)",LVCFMT_LEFT,75);
m_driverlist.InsertColumn(5,"可用(%)",LVCFMT_LEFT,75);
return true;
}
void CSystemInfoDlg::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 CSystemInfoDlg::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 CSystemInfoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSystemInfoDlg::OnGetsysteminfo()
{
GetOsVersion();
GetMemInfo();
GetDriverInfo();
GetCpuInfo();
}
BOOL CSystemInfoDlg::GetCpuInfo()
{
CRegKey rk;
HKEY m_hKey;
DWORD pCount=1024;
CString KeyValue;
char szValue[1024];
LPCTSTR lp="HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0";
if(rk.Open(HKEY_LOCAL_MACHINE,lp)== ERROR_SUCCESS)
{
LPCTSTR lKeyName="ProcessorNameString";
if(rk.QueryValue(szValue,lKeyName,& pCount)== ERROR_SUCCESS)
{
KeyValue=szValue;
KeyValue.Replace(" ","");
SetDlgItemText(IDC_CPUINFO,"CPU信息:"+KeyValue);
}
else
{
SetDlgItemText(IDC_CPUINFO,"Query error");
}
//rk.SetValue(lKeyName,"HH");
}
else
{
SetDlgItemText(IDC_CPUINFO,"Open error");
}
rk.Close();
return true;
}
BOOL CSystemInfoDlg::GetDriverInfo()
{
_ULARGE_INTEGER result_freespace,result_totalspace,result_g;
int error = 0;
int free_space,total_space;
int free_percent;
int used_percent;
int dirvernum=0;
int cdnum=0;
int renum=0;
CString strdir;
CString driverlist="";
CString disk;
CString disk_space;
int totalbulk=0;
int freebulk=0;
for(char cc='A';cc<='Z';cc++)
{
strdir.Format("%c:",cc);
if(GetDriveType((LPCTSTR)strdir)==DRIVE_FIXED)
{
driverlist+=strdir;
dirvernum++;
}
else if(GetDriveType((LPCTSTR)strdir)==DRIVE_CDROM)
{
driverlist+=strdir;
dirvernum++;
cdnum++;
}
else if(GetDriveType((LPCTSTR)strdir)==DRIVE_REMOVABLE)
{
driverlist+=strdir;
dirvernum++;
renum++;
}
}
m_driverlist.DeleteAllItems();
int n_t=0;
for(int n=0;n<dirvernum;n++)
{
disk=driverlist.Mid(n_t,2);
int disktype=GetDriveType((LPCTSTR)disk);
GetDiskFreeSpaceEx(disk,&result_freespace,&result_totalspace,&result_g);
if (error != 0)
{
CString t;
t.Format("GetDiskFreeSpace() error=%d",error);
// AfxMessageBox(t);
}
free_space = result_freespace.QuadPart/1024/1024;
total_space = result_totalspace.QuadPart/1024/1024;
used_percent = (float)(total_space-free_space)/total_space*100;
free_percent = 100-used_percent;
if(disktype==3)
{
totalbulk+=total_space;
freebulk+=free_space;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -