📄 smartdlg.cpp
字号:
// SMARTDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SMART.h"
#include "SMARTDlg.h"
#include ".\smartdlg.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()
/////////////////////////////////////////////////////////////////////////////
// CSMARTDlg dialog
CSMARTDlg::CSMARTDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSMARTDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSMARTDlg)
// 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 CSMARTDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSMARTDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSMARTDlg, CDialog)
//{{AFX_MSG_MAP(CSMARTDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_READ, OnRead)
//}}AFX_MSG_MAP
ON_NOTIFY(NM_RCLICK, IDC_LIST1, OnNMRclickList1)
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnNMDblclkList1)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSMARTDlg message handlers
BOOL CSMARTDlg::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
char *pColumnHeading[]={"AttibId","Name","Value","Worst","RAW","Threshold"};
double dColumnWidth[]={0.1,0.4,0.1,0.1,0.2,0.1};
int nC1,nCount,nWidth;RECT rcList;
CListCtrl *pList1=(CListCtrl*)GetDlgItem(IDC_LIST1);
pList1->DeleteAllItems();
pList1->SetExtendedStyle(pList1->GetExtendedStyle()|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LVS_EX_GRIDLINES);
nCount=pList1->GetHeaderCtrl()->GetItemCount();
// Delete all of the columns.
for(nC1=0;nC1<nCount;nC1++)
pList1->DeleteColumn(0);
pList1->GetClientRect(&rcList);
for(nC1=0;nC1<6;++nC1)
{
nWidth=(int)(rcList.right *dColumnWidth[nC1]);
pList1->InsertColumn(nC1,pColumnHeading[nC1],LVCFMT_LEFT,nWidth);
}
CheckSMART();
return TRUE; // return TRUE unless you set the focus to a control
}
VOID CSMARTDlg::CheckSMART()
{
ST_DRIVE_INFO *pDriveInfo=NULL;
BYTE ucT1,ucT2,ucT3,ucT4;
ST_SMART_INFO *pSmartInfo=NULL;
ST_SMART_DETAILS *pSmartDetails=NULL;
ST_IDSECTOR *pSectorInfo=NULL;
char szT1[MAX_PATH];
CListCtrl *pList1=(CListCtrl*)GetDlgItem(IDC_LIST1);
GetDlgItem(IDC_STATUS)->SetWindowText("Reading SMART Values");
m_oSmartReader.ReadSMARTValuesForAllDrives();
GetDlgItem(IDC_STATUS)->SetWindowText("");
pList1->DeleteAllItems();
for(ucT1=0,ucT4=0;ucT1<m_oSmartReader.m_ucDrivesWithInfo;++ucT1)
{
wsprintf(szT1,"");pList1->InsertItem(ucT4,szT1);
wsprintf(szT1,">>>>>>>>>>>>>>> Drive %d <<<<<<<<<<<<<<<<",ucT1);
pList1->SetItemText(ucT4++,1,szT1);
pSectorInfo=&m_oSmartReader.m_stDrivesInfo[ucT1].m_stInfo;
pList1->InsertItem(ucT4,"");pList1->SetItemText(ucT4,1,"Model");
pList1->SetItemText(ucT4++,4,(PCHAR)pSectorInfo->sModelNumber);
pList1->InsertItem(ucT4,"");pList1->SetItemText(ucT4,1,"Serial");
pList1->SetItemText(ucT4++,4,(PCHAR)pSectorInfo->sSerialNumber);
pList1->InsertItem(ucT4,"");pList1->SetItemText(ucT4,1,"Cache / Buffer");
wsprintf(szT1,"%d (%d)",pSectorInfo->wBufferSize,pSectorInfo->wBufferType);
pList1->SetItemText(ucT4++,4,szT1);
pDriveInfo=m_oSmartReader.GetDriveInfo(ucT1);
for(ucT2=ucT3=0;ucT2<255;++ucT2)
{
pSmartInfo=m_oSmartReader.GetSMARTValue(pDriveInfo->m_ucDriveIndex,ucT2);
if(pSmartInfo)
{
pSmartDetails=m_oSmartReader.GetSMARTDetails(pSmartInfo->m_ucAttribIndex);
if(pSmartDetails)
{
if(pSmartDetails->m_bCritical)
wsprintf(szT1,"%03d (CR)",pSmartDetails->m_ucAttribId);
else
wsprintf(szT1,"%03d",pSmartDetails->m_ucAttribId);
pList1->InsertItem(ucT4,szT1);
wsprintf(szT1,"%s",pSmartDetails->m_csAttribName);
pList1->SetItemText(ucT4,1,szT1);
wsprintf(szT1,"%d",pSmartInfo->m_ucValue);
pList1->SetItemText(ucT4,2,szT1);
wsprintf(szT1,"%d",pSmartInfo->m_ucWorst);
pList1->SetItemText(ucT4,3,szT1);
wsprintf(szT1,"%d",pSmartInfo->m_dwAttribValue);
pList1->SetItemText(ucT4,4,szT1);
wsprintf(szT1,"%d",pSmartInfo->m_dwThreshold);
pList1->SetItemText(ucT4,5,szT1);
ucT4++;
}
}
}
wsprintf(szT1,"");pList1->InsertItem(ucT4++,szT1);
}
}
void CSMARTDlg::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 CSMARTDlg::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 CSMARTDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSMARTDlg::OnRead()
{
CheckSMART();
}
void CSMARTDlg::OnNMRclickList1(NMHDR *pNMHDR, LRESULT *pResult)
{
*pResult = 0;
}
void CSMARTDlg::OnNMDblclkList1(NMHDR *pNMHDR, LRESULT *pResult)
{
CListCtrl *pList1=(CListCtrl*)GetDlgItem(IDC_LIST1);
char szT1[MAX_PATH]={0};
CString csT1;
POSITION ptPos=pList1->GetFirstSelectedItemPosition();
ST_SMART_DETAILS *pSmartDetails=NULL;
if(ptPos)
{
int nItem = pList1->GetNextSelectedItem(ptPos);
pList1->GetItemText(nItem,0,szT1,MAX_PATH);
if(lstrlen(szT1))
{
pSmartDetails=m_oSmartReader.GetSMARTDetails(atoi(szT1));
if(pSmartDetails)
{
pList1->GetItemText(nItem,1,szT1,MAX_PATH);
csT1.Format("%s : %s",szT1,pSmartDetails->m_csAttribDetails);
AfxMessageBox(csT1,MB_ICONINFORMATION);
}
}
}
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -