---------------------------------------------------------------------------VC Post WwW.CcTry.CoM more than a minute to learn, so that your life more exciting! C, C + +, VC + + various learning resources, free tutorials, look forward to your joining! Animation tutorial Just play the role of technical exchange, Please do not use this method for illegal purposes. Any consequences caused by this animation are not related to the animation author and the site.----------------------------------------------------------------------------------- -----Everybody, I am syc today's tutorial is: VC + + basic class []---System Information acquisition------------------------------------------Begin----------------- ----------------------- ①, gets the name of the currently logged on User: function: getusername, to be exact, this function is to get the user name associated with the current thread; ②, Get computer Name: The function is: GetComputerName, of course, you can also use the Setcomputername function to set the computer name, but you must restart the system! ③, getting the description of the CPU: CString getcpudescription () { cstring Strcpu; hkey HKEY = Null; long Lret = RegOpenKeyEx (hkey_local_machine, _t ("hardware\\description\\system\\centralprocessor\\0"), 0, KEY_QUERY_ VALUE, &hkey); if (Lret = = ERROR_SUCCESS) { DWORD dwsize = 0; BYTE *pszbuf = null; Lret = RegQuer Yvalueex (HKey, _t ("processornamestring"), NULL, NULL, NULL, &dwsize); if (Lret = = Error_sucCess && dwsize > 0) { pszbuf = new byte[dwsize+1]; zeromemory (Pszbuf, dwsize+1); regqueryvalueex (HKey, _t ("processornamestring"), NULL, NULL, PSZBUF, &dwsize); } RegCloseKey ( HKey); Strcpu.format (_t ("%s"), Pszbuf); if (pszbuf) Delete [] Pszbuf; } return strcpu;} ④, getting memory information: Ulonglong Getmemoryinfo () { ulonglong Dwmemspace = 0; memorystatusex MemStatus = {0}; memstatus.dwlength = sizeof (memorystatusex); globalmemorystatusex (&memstatus); dwmemspace = ( ULONGLONG) (memstatus.ulltotalphys/1024/1024); return Dwmemspace;} ⑤, get disk list and capacity information: Computer storage units: Byte, KB, MB, GB, TB, PB, EB, ZB, YB, DB, nb//////////////////////////////////////////////// CString enumdrives () { uint ncount = 0; cstring Strdrives; tchar *pbuf = null; //In principle 4*26+1 size is sufficient, each drive character occupies 4 characters, namely: C:\\0 tchar Szbuf[max_path] = {0}; dword Dwret = GetLogicalDriveStrings (MAX_path, szbuf); if (Dwret! = 0) { ncount = dwret/4; PBuf = szbuf; for (UINT idx = 0; idx < ncount; ++idx, PBuf + = 4) { strdrives.appendformat (_t ("%s%s"), PBuf, _t ("\ r \ n")); } } return Strdrives;} cstring getdrivetypestring (CString strdrive) { //pass parameters to at least include: drive letter +: //can also be the path to the directory, but the end must have \ \ symbols CString Strdrivetpye; uint utype = GetDriveType (strdrive); switch (Utype) { case DRIVE_UNKNOWN: Strdrivetpye = _t ("Type unknown! "); break; case drive_no_root_dir: Strdrivetpye = _t (" The specified drive letter does not exist!) "); break; case drive_removable: Strdrivetpye = _t (" Floppy disk or USB flash drive "); break; case DRIVE_FIXED: Strdrivetpye = _t ("Local hard drive or removable hard disk"); break; case drive_remote: Strdrivetpye = _t ("network Disk"); Break; case drive_cdrom: Strdrivetpye = _t ("CD-ROM"); break; case drive_ramdisk: Strdrivetpye = _t ("RAM disk"); break; default: break; } return Strdrivetpye;} cstring Getdrivespaceinfo (CString strdrive) { cstring Strinfo; ularge_integer nFreeBytesAvailable = { 0}; ularge_integer ntotalnumberofbytes = {0}; ularge_integer ntotalnumberoffreebytes = {0}; if ( GetDiskFreeSpaceEx (strdrive, &nfreebytesavailable, &ntotalnumberofbytes, &ntotalnumberoffreebytes)) { //units are bytes //strinfo.format (_t ("Usable capacity:%i64u byte\r\n Total Capacity:%i64u byte\r\n all available capacity:%i64u Byte"), // Nfreebytesavailable.quadpart, Ntotalnumberofbytes.quadpart, Ntotalnumberoffreebytes.quadpart); // Units are gb long double dfreebytesavailable = ((long double) (Nfreebytesavailable.quadpart))/(1024*1024*1024); Long Double dtotalnumberofbytes = ((long double) (Ntotalnumberofbytes.quadpart))/(1024*1024*1024); long double Dtotalnumberoffreebytes = ((long double) (Ntotalnumberoffreebytes.quadpart))/(1024*1024*1024); Strinfo.format (_t ("Usable capacity:%.2LF gb\r\n Total Capacity:%.2LF gb\r\n all available capacity:%.2lf GB"), dfreebytesavailable, Dtotalnumberofbytes, dtotalnumberoffreebytes); } return StrInfo;}
VC + + basic class []---access to system information