c++获得cpu厂商_C/C++获取CPU等硬件信息&&屏幕截图

1 #include "HardwareInfo.h"23 int main(void)4 {56 LPSTR lpCPUName =GetCPUName();7 LPSTR lpCPUManu =GetCPUManufacturer();8 LPSTR lpSoundCarName =GetSoundCarName();9 printf("处理器: %s\n\n"...
摘要由CSDN通过智能技术生成

1 #include "HardwareInfo.h"

2

3 int main(void)4 {5

6 LPSTR lpCPUName =GetCPUName();7 LPSTR lpCPUManu =GetCPUManufacturer();8 LPSTR lpSoundCarName =GetSoundCarName();9 printf("处理器: %s\n\n", lpCPUName);10 printf("CPU制造商: %s\n\n", lpCPUManu);11 printf("声卡: %s\n\n", lpSoundCarName);12 floatused, usable, total;13 GetDiskSpaceInfo("D:", &used, &usable, &total);14 printf("D盘 已用: %.1fG, 可用:%.1fG, 总大小:%.1fG\n\n", used, usable, total);15 printf("运行内存: %.1fG, 已用%d%%\n\n", GetSysRam(), GetRamProportion());16 LPSTR lpStartTime =GetSysStartTime();17 printf("已开机: %s\n\n", GetSysStartTime());18 LPSTR lpSysVer = GetSysInfo(0, 0, 1, 1, 1);19 printf("系统版本: %s\n\n", lpSysVer);20 free(lpCPUName);21 free(lpCPUManu);22 free(lpSoundCarName);23 free(lpStartTime);24 free(lpSysVer);25

26 Sleep(1000);27 DWORD dwLen = 0;28 char *lpData =NULL;29

30 dwLen = PrtScr(&lpData);31 FILE *wj =NULL;32 fopen_s(&wj, "c:\\1.bmp", "wb");33 fwrite(lpData, dwLen, 1, wj);34 fclose(wj);35 free(lpData);36 system("c:\\1.bmp");37 system("pause");38 return 0;39 }40

41 DWORD PrtScr(PCHAR *lpData, HWND hWnd)42 {43 HDC hdcScreen, hdcMem;44 RECT rc = { 0 }, desRc = { 0};45 HBITMAP hbmScreen =NULL;46 BITMAP bmpScreen = { 0};47 BITMAPINFOHEADER bitInfo = { 0};48 BITMAPFILEHEADER bitHead = { 0};49 DWORD dwBmpSize, dwSizeofDIB;50 char *lpbitmap =NULL;51 intwidth, height;52

53 if (!hWnd)54 hWnd =GetDesktopWindow();55 GetWindowRect(hWnd, &rc);56 GetWindowRect(GetDesktopWindow(), &desRc);57

58 hdcScreen =GetDC(NULL);59 hdcMem =CreateCompatibleDC(hdcScreen);60 if (!hdcMem)61 return 0;62 hbmScreen = CreateCompatibleBitmap(hdcScreen, rc.right - rc.left, rc.bottom -rc.top);63 if (!hbmScreen)64 return 0;65 SelectObject(hdcMem, hbmScreen);66 width = (rc.right > desRc.right) ? (desRc.right - rc.left) : (rc.right -rc.left);67 height = (rc.bottom > desRc.bottom) ? (desRc.bottom - rc.top) : (rc.bottom -rc.top);68 if (!BitBlt(hdcMem, 0, 0, width, height, hdcScreen, rc.left, rc.top, SRCCOPY))69 return 0;70 GetObject(hbmScreen, sizeof(BITMAP), &bmpScreen);71

72 bitInfo.biSize = sizeof(BITMAPINFOHEADER);73 bitInfo.biWidth =width;74 bitInfo.biHeight =height;75 bitInfo.biPlanes = 1;76 bitInfo.biBitCount = 32;77 bitInfo.biCompression =BI_RGB;78

79 dwBmpSize = ((bmpScreen.bmWidth * bitInfo.biBitCount + 31) / 32) * 4 *bmpScreen.bmHeight;80 lpbitmap = (char *)malloc(dwBmpSize);81 if (!lpbitmap)82 return 0;83 GetDIBits(hdcScreen, hbmScreen, 0, (UINT)bmpScreen.bmHeight, lpbitmap, (BITMAPINFO *)&bitInfo, DIB_RGB_COLORS);84

85 dwSizeofDIB = dwBmpSize + sizeof(bitHead)+sizeof(bitInfo);86 bitHead.bfOffBits = (DWORD)sizeof(bitHead)+(DWORD)sizeof(bitInfo);87 bitHead.bfSize =dwSizeofDIB;88 //必须是字符BM或者十六进制代替0x4D42="BM"

89 bitHead.bfType = MAKEWORD('B', 'M');90

91 *lpData = (char *)malloc(dwSizeofDIB);92 if (!*lpData)93 return 0;94 memmove(*lpData, &bitHead, siz

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值