The problem is that although the image is created, there is a small indent on the left side, a screenshot is attached (on top is the image that my program makes, just below the program itself).
HDC hdcWindow{ HdcWindowScreen }, hdcMemDC{ CreateCompatibleDC(hdcWindow) };
HBITMAP hbmScreen{};
BITMAP bmpScreen{};
RECT rcClient;
GetClientRect(WindowFromDC(hdcWindow), &rcClient);
hbmScreen = CreateCompatibleBitmap(hdcWindow, rcClient.right + rcClient.left, rcClient.bottom + rcClient.top);
SelectObject(hdcMemDC, hbmScreen);
if (!(BitBlt(hdcMemDC, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, hdcWindow, 0, 0, SRCCOPY))) {
MessageBox(hWnd, L"BitBlt has failed", L"Failed", MB_OK);
ClearMemory();
}
GetObject(hdcWindow, sizeof(BITMAP), &bmpScreen);
BITMAPFILEHEADER bmfHeader{};
BITMAPINFOHEADER bi{};
bi.biSize = sizeof(BITMAPFILEHEADER);
bi.biWidth = bmpScreen.bmWidth;
bi.biHeight = bmpScreen.bmHeight;
bi.biPlanes = 1;
bi.biBitCount = 32;;
bi.biCompression = BI_RGB;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
DWORD dwBmpSize = ((bmpScreen.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmpScreen.bmHeight;
DWORD dwSizeofDIB = dwBmpSize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bmfHeader.bfOffBits = static_cast<DWORD>(sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER));
bmfHeader.bfSize = dwSizeofDIB;
bmfHeader.bfType = 0x4D42;
GdiplusStartupInput gdiplusStartupInput{};
ULONG_PTR gdiplusToken{};
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
CLSID myClsId{};
Bitmap* image = new Bitmap(hbmScreen, nullptr);
image->Save(FileName, &myClsId, NULL);
Gdiplus::GdiplusShutdown(gdiplusToken);