成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

C++使用MFC獲取PC硬件配置信息-創(chuàng)新互聯(lián)

本文實例為大家分享了C++使用MFC獲取PC硬件配置信息的具體代碼,供大家參考,具體內(nèi)容如下

為木壘哈薩克等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及木壘哈薩克網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為網(wǎng)站制作、網(wǎng)站設(shè)計、木壘哈薩克網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!

函數(shù)如下, 使用VS2010編譯通過,在XP和Win7電腦上運行過,被注釋的loop 循環(huán)用于測試此方法是否穩(wěn)定:

//包含的頭文件:
#include "afxdialogex.h"
#include <windows.h>
#include <sstream>
#include <fstream>

void Cget_systemDlg::OnBnClickedButton1()
{
 //for (int i = 0; i < 10000; i++) {

 std::ostringstream osConfig;
 osConfig.precision(1);

 // Computer Name
 TCHAR infoBuf[512] = {0};
 DWORD bufCharCount = 512;
 if (GetComputerName(infoBuf, &bufCharCount)) // MSDN: If the function succeeds, the return value is a nonzero value.
  osConfig << "Computer Name: " << infoBuf << std::endl;
 else
  osConfig << "!Error: failed to get computer name" << std::endl;

 // CPU 
 CString strPath = CString("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"); 
 CRegKey regKey; 
 LONG lResult; 
 lResult = regKey.Open(HKEY_LOCAL_MACHINE, strPath, KEY_READ); 
 if (lResult == ERROR_SUCCESS) 
 {  
  TCHAR chCPUName[256] = {0}; 
  DWORD dwSize = 256; 
  LPCSTR name = "ProcessorNameString";
  regKey.QueryValue(chCPUName,_T("ProcessorNameString"),&dwSize);  
  osConfig << "CPU Type: " << (char*)chCPUName << std::endl;
  regKey.Close(); 
 } 
 else
  osConfig << "!Error: failed to open register for read CPU." << std::endl;

 // OS Name
 char szOsType[MAX_PATH];
 HKEY hKey;
 LPCTSTR StrKey="Software\\Microsoft\\Windows NT\\CurrentVersion";
 if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_LOCAL_MACHINE,StrKey,NULL,KEY_READ,&hKey))
 {
  DWORD dwSize = 255;
  DWORD dwType = REG_SZ;
  LPCSTR KeyValue = "ProductName";
  if (ERROR_SUCCESS == ::RegQueryValueEx(hKey,KeyValue,0,&dwType,(BYTE *)szOsType,&dwSize))
   osConfig << "OS : " << szOsType;
  else
   osConfig << "!Error: failed to get OS name." << std::endl;
  ::RegCloseKey(hKey);
 }
 else 
  osConfig << "!Error: failed to get OS name." << std::endl;

 SYSTEM_INFO si;
 GetNativeSystemInfo(&si); // MSDN: This function does not return a value.
 if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )
  osConfig << " 64bits";
 else
  osConfig << " 32bits";

 OSVERSIONINFO osVer;
 osVer.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
 if (::GetVersionEx (&osVer)) // MSDN: If the function succeeds, the return value is a nonzero value.
  osConfig << " " << osVer.szCSDVersion << " " << std::endl;
 else
  osConfig << "!Error: failed to get OS CSD version.";

 // Memory
 MEMORYSTATUSEX statusex;
 statusex.dwLength = sizeof (statusex);
 if (GlobalMemoryStatusEx(&statusex)) // MSDN: If the function succeeds, the return value is nonzero.
 {
  osConfig << "Installed RAM: "<< std::fixed << statusex.ullTotalPhys /1024/1024/1024.0 << "GB";
  osConfig << " Free RAM: " << std::fixed << statusex.ullAvailPhys/1024/1024/1024.0 << "GB" << std::endl;
 }
 else
  osConfig << "!Error: failed to get RAM information." << std::endl;

 // Hard Drive
 // GetLogicalDriveStrings(sizeof(cDriveArray), cDriveArray);
 // MSDN: If the function fails, the return value is zero. 
 // If the function succeeds, the return value is the length, in characters, of the strings copied to the buffer, 
 // not including the terminating null character
 ULARGE_INTEGER free;
 ULARGE_INTEGER total;
 ULARGE_INTEGER totalfree;
 TCHAR szDriveArray[128] = {0};
 TCHAR *p, *pStart;
 pStart = szDriveArray;
 p = szDriveArray;
 int nLen = GetLogicalDriveStrings(sizeof(szDriveArray), szDriveArray);
 if (nLen !=0 ) 
 {
  while ((p = _tcschr(p, _T('\0'))) && p != szDriveArray + nLen )
  {
   if (GetDiskFreeSpaceEx(pStart, &free, &total, &totalfree)) // if success, nonzero
   {
    osConfig << "[" << pStart << "]" << " Total: " << std::fixed << total.QuadPart/1024/1024/1024.0 
     << "GB Available: " << std::fixed << free.QuadPart/1024/1024/1024.0 << "GB";
    if (GetDriveType(pStart) == 3)
     osConfig <<" - Fixed Drive" << std::endl;
    else if (GetDriveType(pStart) == 4)
     osConfig <<" - (Remote Drive)" << std::endl;
    else
     osConfig <<" - Other" << std::endl;
   }
   pStart = ++p; 
  }
 }
 else
  osConfig << "!Error: failed to get logical drive name." << std::endl;

 AfxMessageBox(osConfig.str().c_str());

 //std::ostringstream file;
 //file << i << ".txt";
 //std::ofstream log(file.str().c_str());

 //log << osConfig.str().c_str();
 //log.close();
 //log.clear();

 //}
 AfxMessageBox("DONE");
}

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站jinyejixie.com,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

本文標(biāo)題:C++使用MFC獲取PC硬件配置信息-創(chuàng)新互聯(lián)
文章出自:http://jinyejixie.com/article12/piigc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、網(wǎng)站改版、網(wǎng)站維護、標(biāo)簽優(yōu)化、App設(shè)計、網(wǎng)站策劃

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)
敖汉旗| 莎车县| 金坛市| 林芝县| 忻州市| 沧源| 竹北市| 布尔津县| 宜章县| 明水县| 忻州市| 海丰县| 兰考县| 内丘县| 民权县| 沙田区| 正镶白旗| 民丰县| 德惠市| 桑日县| 襄垣县| 株洲市| 长寿区| 巴里| 平和县| 南宁市| 兴海县| 河曲县| 滨海县| 扬中市| 定州市| 井陉县| 木里| 昔阳县| 漾濞| 玉田县| 安岳县| 泗水县| 鄂伦春自治旗| 中卫市| 秭归县|