请教一个分层窗口的截不出来的问题

2016-07-20 21:31:17 +08:00
 tghgffdgd

之前一直是少了个参数然后不行,可是后来参数加了也不行,后面误打误撞换了写法发现可以。 不知道是哪里出了问题,代码差别在哪里。

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);//获取分层窗口成功
...
}
1629 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/293798

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX