下面是我的代码:
int main()
{
HDESK desktop;
desktop = GetThreadDesktop(GetCurrentThreadId());
EnumDesktopWindows(desktop, EnumWindowsProc, 0);
return 0;
}
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
RECT rc;
char buff[1024];
GetWindowRect(hwnd, &rc);
HDC hdcScreen = GetDC(hwnd);
HDC hdcCompatible = CreateCompatibleDC(hdcScreen);
HBITMAP hbmScreen = CreateCompatibleBitmap(hdcScreen, rc.right - rc.left, rc.bottom - rc.top);
SelectObject(hdcCompatible, hbmScreen);
PrintWindow(hwnd, hdcCompatible, NULL);
wsprintfA(buff, "T:\\%dx%d - %dx%d.bmp", rc.left, rc.right, rc.top, rc.bottom);
CreateBMPFile(buff, hbmScreen, hdcCompatible);
return true;
}
一切正常。但是,它也可以保存内部为黑色的垃圾图像。我该如何解决?我只有一个窗口打开。它将其保存到bmp
。但是很多垃圾图像里面都是黑色的。