[英]Showing window content as bitmap
i want to take a image of window's content and show it as smaller bitmap in that window... i followed this article: http://msdn.microsoft.com/en-us/library/dd183402(v=vs.85).aspx and when i want take screenshot of whole desktop - it works fine... problem is when i try to get bitmap only of window's content. 我想拍摄窗口内容的图像并将其显示为该窗口中的较小位图...我关注了这篇文章: http : //msdn.microsoft.com/zh-cn/library/dd183402(v=vs.85) .aspx ,当我想获取整个桌面的屏幕截图时,它可以正常工作...问题是当我尝试仅获取窗口内容的位图时。 Any ideas what am I doing wrong ?
有什么想法我做错了吗?
Here's my code: 这是我的代码:
HDC hDC;
HDC hDCMemDC = NULL;
HBITMAP hbmWindow = NULL;
BITMAP bmpWindow;
hDC = GetDC(hWnd);
hDCMemDC = CreateCompatibleDC(hDC);
RECT clientRect;
GetClientRect(hWnd, &clientRect);
hbmWindow = CreateCompatibleBitmap(hDC, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top);
SelectObject(hDCMemDC, hbmWindow);
BitBlt(hDCMemDC, 0, 0, 100, 100, hDC, 0, 0, SRCCOPY);
Thanks 谢谢
void DrawSelf(HDC Context, RECT Area, RECT NewArea)
{
uint32_t W = Area.right - Area.left;
uint32_t H = Area.bottom - Area.top;
uint32_t NW = NewArea.right - NewArea.left;
uint32_t NH = NewArea.bottom - NewArea.top;
StretchBlt(Context, NewArea.left, NewArea.top, NW, NH, Context, Area.left, Area.top, W, H, SRCCOPY);
}
Then you can do: 然后,您可以执行以下操作:
RECT Area;
RECT Area2;
HDC DC = GetDC(hwnd); //Gets the client area only.. Use GetWindowDC for the whole window including the title-bar.
GetClientRect(hwnd, &Area); //client area only.
GetClientRect(hwnd, &Area2);
//Smaller area in which to draw.
Area2.left += 5;
Area2.right -= 5;
Area2.top += 5;
Area2.bottom -= 5;
DrawSelf(DC, Area, Area2);
ReleaseDC(hwnd, dc);
使用GetWindowDC而不是GetDC来获取整个窗口区域。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.