📄 diskserialdlg.cpp
字号:
// DiskSerialDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DiskSerial.h"
#include "DiskSerialDlg.h"
#include "disk.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDiskSerialDlg dialog
CDiskSerialDlg::CDiskSerialDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDiskSerialDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDiskSerialDlg)
m_no = 0;
m_a = _T("");
m_b = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CDiskSerialDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDiskSerialDlg)
DDX_Text(pDX, IDC_EDIT1, m_no);
DDX_Text(pDX, IDC_EDIT2, m_a);
DDX_Text(pDX, IDC_EDIT3, m_b);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDiskSerialDlg, CDialog)
//{{AFX_MSG_MAP(CDiskSerialDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDiskSerialDlg message handlers
BOOL CDiskSerialDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
}
// 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 CDiskSerialDlg::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 CDiskSerialDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDiskSerialDlg::OnButton1()
{
// TODO: Add your control notification handler code here
BYTE szDiskModel[100]; // 在程序执行完毕后,此处存储取得的系统特征码
BYTE szDiskSerial[100];
// 硬盘序列号,注意:有的硬盘没有序列号
UpdateData();
OSVERSIONINFO ovi = { 0 };
ovi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
GetVersionEx( &ovi );
if( ovi.dwPlatformId != VER_PLATFORM_WIN32_NT )
{
// Only Windows 2000, Windows XP, Windows Server 2003...
return ;
}
else
{
if( !WinNTHDSerialNumAsPhysicalRead( szDiskModel, szDiskSerial, m_no) )
{
WinNTHDSerialNumAsScsiRead( szDiskModel, szDiskSerial, m_no);
}
}
for(int i=0;i<20;i+=2)
{
byte c;
c=szDiskSerial[i];
szDiskSerial[i]=szDiskSerial[i+1];
szDiskSerial[i+1]=c;
}
szDiskSerial[i]=0;
for(i=0;i<40;i+=2)
{
byte c;
c=szDiskModel[i];
szDiskModel[i]=szDiskModel[i+1];
szDiskModel[i+1]=c;
}
szDiskModel[i]=0;
m_a.Empty();
m_a+=(char *)szDiskModel;
m_a.TrimRight();
m_a.TrimLeft();
m_b.Empty();
m_b+=(char *)szDiskSerial;
m_b.TrimLeft();
m_b.TrimRight();
UpdateData(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -