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