📄 12dlg.cpp
字号:
// 12Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "12.h"
#include "12Dlg.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()
/////////////////////////////////////////////////////////////////////////////
// CMy12Dlg dialog
CMy12Dlg::CMy12Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CMy12Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMy12Dlg)
m_edit = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
BOOL CMy12Dlg::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;
}
if(!IsDlgButtonChecked(IDC_USEGBTYPE))
{
m_driverlist.InsertItem(n,(disktype==3?"(硬)":(disktype==2?"(移)":(disktype==5?"(光)":"(未)")))+driverlist.Mid(n_t,2),NULL);
disk_space.Format("%d",total_space);
m_driverlist.SetItemText(n,1,disk_space+" MB");
disk_space.Format("%d",total_space-free_space);
m_driverlist.SetItemText(n,2,disk_space+" MB");
disk_space.Format("%d",free_space);
m_driverlist.SetItemText(n,3,disk_space+" MB");
}
else
{
CString info="";
m_driverlist.InsertItem(n,(disktype==3?"(硬)":(disktype==2?"(移)":(disktype==5?"(光)":"(未)")))+driverlist.Mid(n_t,2),NULL);
info.Format("%f",(float)total_space/1024);
info=info.Mid(0,info.Find(".",0)+3)+" GB";
m_driverlist.SetItemText(n,1,info);
info.Format("%f",(float)(total_space-free_space)/1024);
info=info.Mid(0,info.Find(".",0)+3)+" GB";
m_driverlist.SetItemText(n,2,info);
info.Format("%f",(float)free_space/1024);
info=info.Mid(0,info.Find(".",0)+3)+" GB";
m_driverlist.SetItemText(n,3,info);
}
disk_space.Format("%d",used_percent);
m_driverlist.SetItemText(n,4,disk_space+"%");
disk_space.Format("%d",free_percent);
m_driverlist.SetItemText(n,5,disk_space+"%");
n_t+=2;
}
////////////////磁盘信息
strdir.Format("硬盘驱动器 %d 个,光盘驱动器 %d 个,可移动驱动器 %d 个",dirvernum-cdnum-renum,cdnum,renum);
SetDlgItemText(IDC_DRIVERINFO,strdir);
if(IsDlgButtonChecked(IDC_USEGBTYPE))
{
strdir.Format("硬盘总大小为 %dGB,已用 %dGB, 可用 %dGB",totalbulk/1024,(totalbulk-freebulk)/1024,freebulk/1024);
}
else
{
strdir.Format("硬盘总大小为 %dMB,已用 %dMB, 可用 %dMB",totalbulk,totalbulk-freebulk,freebulk);
}
SetDlgItemText(IDC_HARDDISKINFO,strdir);
return true;
}
BOOL CMy12Dlg::InitDriverList()
{
for(int n=0;n<10;n++)
{
m_driverlist.DeleteColumn(n);
}
m_driverlist.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
m_driverlist.InsertColumn(0,"驱动器",LVCFMT_LEFT,50);
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 CMy12Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMy12Dlg)
DDX_Control(pDX, IDC_DRIVERLIST, m_driverlist);
DDX_Text(pDX, IDC_EDIT, m_edit);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMy12Dlg, CDialog)
//{{AFX_MSG_MAP(CMy12Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_NOTIFY(HDN_ITEMCLICK, IDC_DRIVERLIST, OnItemclickDriverlist)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy12Dlg message handlers
BOOL CMy12Dlg::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
InitDriverList();
GetDriverInfo();
return TRUE; // return TRUE unless you set the focus to a control
}
void CMy12Dlg::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 CMy12Dlg::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 CMy12Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMy12Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
GetDriverInfo();
}
void CMy12Dlg::OnItemclickDriverlist(NMHDR* pNMHDR, LRESULT* pResult)
{
HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
// TODO: Add your control notification handler code here
// TOD Add your control notification handler code here
/*UpdateData();
POSITION pos=m_driverlist.GetFirstSelectedItemPosition();//获得单击的位置
if(pos)
{
int nFistSelItem=m_driverlist.GetNextSelectedItem(pos);//获得单击条目
// m_edit=m_driverlist.GetItemText(nFistSelItem,1);
m_topic=m_driverlist.GetItemText(nFistSelItem,1);//获得事务主题
CString strSQL;
//得到事务主题后 向数据库读取对应数据
CTransaction transaction;
transaction.GetData(m_topic);
m_chairman=transaction.m_chairman;
m_date=transaction.m_date;
m_note=transaction.m_note;
m_participant=transaction.m_participant;
m_place=transaction.m_place;
m_time=transaction.m_time;
m_topic=transaction.m_topic;
m_type=transaction.m_type;
UpdateData(false);
}
// m_edit.Format();*/
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -