【问题标题】:Showing window content as bitmap将窗口内容显示为位图
【发布时间】:2014-07-15 04:11:35
【问题描述】:

我想拍摄窗口内容的图像并在该窗口中将其显示为较小的位图...我关注了这篇文章: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);

谢谢

【问题讨论】:

  • “我想拍摄窗口内容的图像并在该窗口中显示为较小的位图”——较小的位图将在窗口中与较小位图的位置相对应的位置显示什么?
  • 根本不明白你的问题,但是那个位图是窗口的较小版本......无论如何,我想在窗口中获取形状的图像,删除这些形状并只显示一个位图他们

标签: c++ winapi gdi+


【解决方案1】:
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);

【讨论】:

    【解决方案2】:

    使用 GetWindowDC 而不是 GetDC 来获取整个窗口区域。

    【讨论】:

      猜你喜欢
      • 2015-07-09
      • 2021-03-01
      • 2017-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多