Zi 字媒體
2017-07-25T20:27:27+00:00
[VC(Visual C++) ]- 抓硬碟序號DrvSrlNmbr02
本篇分享抓硬碟序號DrvSrlNmbr02範例,有興趣的(C/P)同好,歡迎來http://yfdisk.com/file/jashliao/f5cabd33/索取,因為我不會上傳檔案分享哈哈 ^ ^。
主要程式碼
001 // DrvSrlNmbrDlg.cpp : implementation file
002 //
003
004 #include "stdafx.h"
005 #include "DrvSrlNmbr.h"
006 #include "DrvSrlNmbrDlg.h"
007
008 #ifdef _DEBUG
009 #definenew DEBUG_NEW
010 #undef THIS_FILE
011 staticchar THIS_FILE[] = __FILE__;
012 #endif
013
014 /////////////////////////////////////////////////////////////////////////////
015 // CAboutDlg dialog used for App About
016
017 class CAboutDlg : public CDialog
018 {
019 public:
020 CAboutDlg();
021
022 // Dialog Data
023 //{{AFX_DATA(CAboutDlg)
024 enum { IDD = IDD_ABOUTBOX };
025 //}}AFX_DATA
026
027 // ClassWizard generated virtual function overrides
028 //{{AFX_VIRTUAL(CAboutDlg)
029 protected:
030 virtualvoid DoDataExchange(CDataExchange* pDX); // DDX/DDV support
031 //}}AFX_VIRTUAL
032
033 // Implementation
034 protected:
035 //{{AFX_MSG(CAboutDlg)
036 //}}AFX_MSG
037 DECLARE_MESSAGE_MAP()
038 };
039
040 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
041 {
042 //{{AFX_DATA_INIT(CAboutDlg)
043 //}}AFX_DATA_INIT
044 }
045
046 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
047 {
048 CDialog::DoDataExchange(pDX);
049 //{{AFX_DATA_MAP(CAboutDlg)
050 //}}AFX_DATA_MAP
051 }
052
053 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
054 //{{AFX_MSG_MAP(CAboutDlg)
055 // No message handlers
056 //}}AFX_MSG_MAP
057 END_MESSAGE_MAP()
058
059 /////////////////////////////////////////////////////////////////////////////
060 // CDrvSrlNmbrDlg dialog
061
062 CDrvSrlNmbrDlg::CDrvSrlNmbrDlg(CWnd* pParent /*=NULL*/)
063 : CDialog(CDrvSrlNmbrDlg::IDD, pParent)
064 {
065 //{{AFX_DATA_INIT(CDrvSrlNmbrDlg)
066 // NOTE: the ClassWizard will add member initialization here
067 //}}AFX_DATA_INIT
068 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
069 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
070 }
071
072 void CDrvSrlNmbrDlg::DoDataExchange(CDataExchange* pDX)
073 {
074 CDialog::DoDataExchange(pDX);
075 //{{AFX_DATA_MAP(CDrvSrlNmbrDlg)
076 // NOTE: the ClassWizard will add DDX and DDV calls here
077 //}}AFX_DATA_MAP
078 }
079
080 BEGIN_MESSAGE_MAP(CDrvSrlNmbrDlg, CDialog)
081 //{{AFX_MSG_MAP(CDrvSrlNmbrDlg)
082 ON_WM_SYSCOMMAND()
083 ON_WM_PAINT()
084 ON_WM_QUERYDRAGICON()
085 ON_BN_CLICKED(IDC_GETSRLNUM, OnGetSrlNum)
086 //}}AFX_MSG_MAP
087 END_MESSAGE_MAP()
088
089 /////////////////////////////////////////////////////////////////////////////
090 // CDrvSrlNmbrDlg message handlers
091
092 BOOL CDrvSrlNmbrDlg::OnInitDialog()
093 {
094 CDialog::OnInitDialog();
095
096 // Add "About..." menu item to system menu.
097
098 // IDM_ABOUTBOX must be in the system command range.
099 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
100 ASSERT(IDM_ABOUTBOX < 0xF000);
101
102 CMenu* pSysMenu = GetSystemMenu(FALSE);
103 if (pSysMenu != NULL)
104 {
105 CString strAboutMenu;
106 strAboutMenu.LoadString(IDS_ABOUTBOX);
107 if (!strAboutMenu.IsEmpty())
108 {
109 pSysMenu->AppendMenu(MF_SEPARATOR);
110 pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
111 }
112 }
113
114 // Set the icon for this dialog. The framework does this automatically
115 // when the application's main window is not a dialog
116 SetIcon(m_hIcon, TRUE); // Set big icon
117 SetIcon(m_hIcon, FALSE); // Set small icon
118
119 // TODO: Add extra initialization here
120
121 //蹈堤垀衄雄
122 FindAllDrivers();
123 CComboBox* Driver=(CComboBox*)GetDlgItem(IDC_DRIVER);
124 Driver->SetCurSel(0);
125 return TRUE; // return TRUE unless you set the focus to a control
126 }
127
128 void CDrvSrlNmbrDlg::OnSysCommand(UINT nID, LPARAM lParam)
129 {
130 if ((nID & 0xFFF0) == IDM_ABOUTBOX)
131 {
132 CAboutDlg dlgAbout;
133 dlgAbout.DoModal();
134 }
135 else
136 {
137 CDialog::OnSysCommand(nID, lParam);
138 }
139 }
140
141 // If you add a minimize button to your dialog, you will need the code below
142 // to draw the icon. For MFC applications using the document/view model,
143 // this is automatically done for you by the framework.
144
145 void CDrvSrlNmbrDlg::OnPaint()
146 {
147 if (IsIconic())
148 {
149 CPaintDC dc(this); // device context for painting
150
151 SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
152
153 // Center icon in client rectangle
154 int cxIcon = GetSystemMetrics(SM_CXICON);
155 int cyIcon = GetSystemMetrics(SM_CYICON);
156 CRect rect;
157 GetClientRect(&rect);
158 int x = (rect.Width() - cxIcon + 1) / 2;
159 int y = (rect.Height() - cyIcon + 1) / 2;
160
161 // Draw the icon
162 dc.DrawIcon(x, y, m_hIcon);
163 }
164 else
165 {
166 CDialog::OnPaint();
167 }
168 }
169
170 // The system calls this to obtain the cursor to display while the user drags
171 // the minimized window.
172 HCURSOR CDrvSrlNmbrDlg::OnQueryDragIcon()
173 {
174 return (HCURSOR) m_hIcon;
175 }
176
177 void CDrvSrlNmbrDlg::OnGetSrlNum()
178 {
179 //載陔狟嶺遺腔雄瘍
180 UpdateData(TRUE);
181
182 //鳳腕狟嶺遺腔硌渀勤砓
183 CComboBox* Driver=(CComboBox*)GetDlgItem(IDC_DRIVER);
184
185 //鳳腕絞恁寁腔雄
186 CString strRootPathName;
187 Driver->GetWindowText(strRootPathName);
188
189 //鳳腕雄唗蹈瘍
190 LPCTSTR lpRootPathName = strRootPathName;
191 LPTSTR lpVolumeNameBuffer=newchar[12];
192 DWORD nVolumeNameSize=12;
193 DWORD VolumeSerialNumber;
194 DWORD MaximumComponentLength;
195 DWORD FileSystemFlags;
196 LPTSTR lpFileSystemNameBuffer=newchar[10];
197 DWORD nFileSystemNameSize=10;
198 GetVolumeInformation(lpRootPathName,
199 lpVolumeNameBuffer, nVolumeNameSize,
200 &VolumeSerialNumber,
201 &MaximumComponentLength,
202 &FileSystemFlags,
203 lpFileSystemNameBuffer, nFileSystemNameSize);
204
205 //珆尨雄唗蹈瘍
206 CString str;
207 str.Format("驅動器%s的序號為%x",strRootPathName,VolumeSerialNumber);
208 AfxMessageBox(str);
209 DWORD data;
210 data=VolumeSerialNumber^663233909;//27882575
211 str="";
212 str.Format("驅動器%s的序號的XOR值%x",strRootPathName,data);
213 AfxMessageBox(str);
214 FILE *pf;
215 pf=fopen("Key_value.dat","w");
216 str="";
217 str.Format("%x",data);
218 fprintf(pf,"%s",str.GetBuffer(0));
219 fclose(pf);
220
221
222 }
223
224 void CDrvSrlNmbrDlg::FindAllDrivers()
225 {
226 CComboBox* Driver=(CComboBox*)GetDlgItem(IDC_DRIVER);
227 DWORD dwNumBytesForDriveStrings;//妗暱湔揣雄瘍腔趼睫揹酗僅
228 HANDLE hHeap;
229 LPSTR lp;
230 CString strLogdrive;
231
232 //鳳腕妗暱湔揣雄瘍腔趼睫揹酗僅
233 dwNumBytesForDriveStrings=GetLogicalDriveStrings(0,NULL)*sizeof(TCHAR);
234
235 //彆趼睫揹祥峈諾ㄛ寀桶尨衄淏都腔雄湔婓
236 if (dwNumBytesForDriveStrings!=0) {
237 //煦饜趼睫揹諾潔
238 hHeap=GetProcessHeap();
239 lp=(LPSTR)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,
240 dwNumBytesForDriveStrings);
241
242 //鳳腕梓隴垀衄雄腔趼睫揹
243 GetLogicalDriveStrings(HeapSize(hHeap,0,lp),lp);
244
245 //蔚雄珨跺跺溫善狟嶺遺笢
246 while (*lp!=0) {
247 Driver->AddString(lp);
248 lp=_tcschr(lp,0)+1;
249 }
250 }
251 else
252 AfxMessageBox("Can't Use The Function GetLogicalDriveStrings!");
253 }
寫了
5860316篇文章,獲得
23313次喜歡