WM_PRINTCLIENT为BMP出来全黑 [英] WM_PRINTCLIENT to BMP coming out all black
本文介绍了WM_PRINTCLIENT为BMP出来全黑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是新来使用MFC和位图工作。我有一个 HWND
,我想打印到使用 WM_PRINTCLIENT
的位图。这是我迄今:
I am new to working with MFC and bitmaps. I have a HWND
, which I want to print onto a bitmap using WM_PRINTCLIENT
. This is what I have thus far:
编辑:
CRect rcWindow;
GetClientRect(hWnd, &rcWindow);
HDC hDC = GetDC(hWnd);
HDC hBitmapDC = CreateCompatibleDC(hDC);
HBITMAP hBitmap = CreateCompatibleBitmap(hDC, rcWindow.Width(), rcWindow.Height());
SelectObject(hBitmapDC, hBitmap);
SendMessage(hWnd, WM_PRINTCLIENT, (WPARAM)hBitmapDC, PRF_CHILDREN | PRF_CLIENT | PRF_NONCLIENT);
CImage image;
image.Attach(hBitmap);
image.Save(_T("C:\\Test.bmp"), Gdiplus::ImageFormatBMP);
然而,这导致了位图,它是全黑的。任何人都可以看到我在做什么错了?
This however results in a bitmap that is all black. Can anyone see what I am doing wrong?
推荐答案
请尝试以下操作:
HDC hBitmapDC = ::CreateCompatibleDC(hDC);
HBITMAP hBitmap = ::CreateCompatibleBitmap(hDC, rcWindow.Width(), rcWindow.Height());
::SelectObject(hBitmapDC, hBitmap);
// Blt the existing background into the bitmap DC
::BitBlt(hBitmapDC,
0, 0, rcWindow.Width(), rcWindow.Height(),
hDC, rcWindow.left, rcWindow.top, SRCCOPY);
不要忘了删除使用:: DeleteObject的使用DeleteDC,位图DC的位图对象,当您与他们完成...
Don't forget to delete the bitmap object using ::DeleteObject, and the bitmap DC using DeleteDC, when you've finished with them...
希望这有助于
这篇关于WM_PRINTCLIENT为BMP出来全黑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文