win32 C++ ScreenShot and save
文章转自王牌软件
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
只回答业务咨询
站长推荐:NSetup一键部署软件
一键式完成美化安装包制作,自动增量升级,数据统计,数字签名。应对各种复杂场景,脚本模块化拆分,常规复杂的脚本代码,图形化设置。无需专业的研发经验,轻松完成项目部署。(www.nsetup.cn)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
BOOL ScreenShot(_In_ LPCWSTR lpFileName) { static HDC hSrcDC; hSrcDC = GetDC(GetDesktopWindow()); int nx = GetSystemMetrics(SM_XVIRTUALSCREEN); int ny = GetSystemMetrics(SM_YVIRTUALSCREEN); int nWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN); int nHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN); if (!nWidth || !nHeight) return FALSE; HDC hMemDC = CreateCompatibleDC(hSrcDC); HBITMAP hBitmap = CreateCompatibleBitmap(hSrcDC, nWidth, nHeight); HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap); BitBlt(hMemDC, 0, 0, nWidth, nHeight, hSrcDC, nx, ny, SRCCOPY | CAPTUREBLT); hBitmap = (HBITMAP)SelectObject(hMemDC, hOldBitmap); PVOID lpvpxldata; DWORD dwBitmapArraySize; DWORD nBitsOffset; DWORD lImageSize; DWORD lFileSize; BITMAPINFO bmInfo; BITMAPFILEHEADER bmFileHeader; HANDLE hbmfile; DWORD dwWritten; dwBitmapArraySize = ((((nWidth * 32) + 31) & ~31) >> 3) * nHeight; lpvpxldata = HeapAlloc(GetProcessHeap(), HEAP_NO_SERIALIZE, dwBitmapArraySize); ZeroMemory(lpvpxldata, dwBitmapArraySize); ZeroMemory(&bmInfo, sizeof(BITMAPINFO)); bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmInfo.bmiHeader.biWidth = nWidth; bmInfo.bmiHeader.biHeight = nHeight; bmInfo.bmiHeader.biPlanes = 1; bmInfo.bmiHeader.biBitCount = 32; bmInfo.bmiHeader.biCompression = BI_RGB; ZeroMemory(&bmFileHeader, sizeof(BITMAPFILEHEADER)); nBitsOffset = sizeof(BITMAPFILEHEADER) + bmInfo.bmiHeader.biSize; lImageSize = ((((bmInfo.bmiHeader.biWidth * bmInfo.bmiHeader.biBitCount) + 31) & ~31) >> 3) * bmInfo.bmiHeader.biHeight; lFileSize = nBitsOffset + lImageSize; bmFileHeader.bfType = 'B' + ('M' << 8); bmFileHeader.bfSize = lFileSize; bmFileHeader.bfOffBits = nBitsOffset; GetDIBits(hMemDC, hBitmap, 0, bmInfo.bmiHeader.biHeight, lpvpxldata, &bmInfo, DIB_RGB_COLORS); hbmfile = CreateFile(lpFileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); WriteFile(hbmfile, &bmFileHeader, sizeof(BITMAPFILEHEADER), &dwWritten, 0); WriteFile(hbmfile, &bmInfo, sizeof(BITMAPINFO), &dwWritten, 0); WriteFile(hbmfile, lpvpxldata, lImageSize, &dwWritten, 0); CloseHandle(hbmfile); HeapFree(GetProcessHeap(), HEAP_NO_SERIALIZE, lpvpxldata); ReleaseDC(GetDesktopWindow(), hSrcDC); DeleteDC(hMemDC); DeleteObject(hBitmap); return TRUE; } |
学习日记,兼职软件设计,软件修改,毕业设计。
本文出自 学习日记,转载时请注明出处及相应链接。
本文永久链接: https://www.softwareace.cn/?p=1301