gpt4 book ai didi

c++ - 将窗口内容显示为位图

转载 作者:行者123 更新时间:2023-11-28 06:47:12 25 4
gpt4 key购买 nike

我想拍摄窗口内容的图像并在该窗口中将其显示为较小的位图...我关注了这篇文章:http://msdn.microsoft.com/en-us/library/dd183402(v=vs.85).aspx当我想截取整个桌面的屏幕截图时 - 它工作正常...问题是当我尝试仅获取窗口内容的位图时。知道我做错了什么吗?

这是我的代码:

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);

谢谢

最佳答案

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);
}

然后你可以这样做:

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);

关于c++ - 将窗口内容显示为位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24749737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com