之前一直是少了个参数然后不行,可是后来参数加了也不行,后面误打误撞换了写法发现可以。 不知道是哪里出了问题,代码差别在哪里。
void CPrintScr::Print()
{
HDC hScrDC = CreateDCW(L"DISPLAY", NULL, NULL, NULL);
const int nWidth = GetDeviceCaps(hScrDC, HORZRES);
const int nHeight = GetDeviceCaps(hScrDC, VERTRES);
m_hMemDC = CreateCompatibleDC(hScrDC);
HBITMAP hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight);
HBITMAP hBmpOld = (HBITMAP)SelectObject(m_hMemDC, hBitmap);
BitBlt(m_hMemDC, 0, 0, nWidth, nHeight, hScrDC, 0, 0, SRCCOPY | CAPTUREBLT);
SelectObject(m_hMemDC, hBmpOld);
DeleteDC(m_hMemDC);
DeleteDC(hScrDC);
SetSavePath(L"c:\\tt.jpg");
SaveBitmapToFile(hBitmap, JPG);//获取分层窗口失败,分层窗口都是透明
...
}
HBITMAP CaptureScreen()
{
HDC hScrDC = CreateDCW(L"DISPLAY", NULL, NULL, NULL);
const int nWidth = GetDeviceCaps(hScrDC, HORZRES);
const int nHeight = GetDeviceCaps(hScrDC, VERTRES);
HDC m_hMemDC = CreateCompatibleDC(hScrDC);
HBITMAP hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight);
HBITMAP hBmpOld = (HBITMAP)SelectObject(m_hMemDC, hBitmap);
BitBlt(m_hMemDC, 0, 0, nWidth, nHeight, hScrDC, 0, 0, SRCCOPY | CAPTUREBLT);
SelectObject(m_hMemDC, hBmpOld);
DeleteDC(m_hMemDC);
DeleteDC(hScrDC);
return hBitmap;
}
{
...
g_PrintScr.SetSavePath(L"c:\\tt2.jpg");
g_PrintScr.SaveBitmapToFile(CaptureScreen(), JPG);//获取分层窗口成功
...
}