【问题标题】:Why BitBlt does not copy the correct part为什么 BitBlt 不复制正确的部分
【发布时间】:2014-02-27 17:09:38
【问题描述】:

当我尝试使用下面的代码将应用程序图标复制到客户区的左上角时,我使用了如下代码:

case WM_PAINT:
    hdcClient = BeginPaint (hwnd, &ps) ;
    hdcWindow = GetWindowDC (hwnd) ;

    cxSource = GetSystemMetrics (SM_CXSIZEFRAME) + GetSystemMetrics (SM_CXSIZE) ;
    cySource = GetSystemMetrics (SM_CYSIZEFRAME) + GetSystemMetrics (SM_CYCAPTION) ;

    BitBlt (hdcClient, 0, 0, cxSource, cySource, hdcWindow, 0, 0, SRCCOPY) ;

    ReleaseDC (hwnd, hdcWindow) ;
    EndPaint (hwnd, &ps) ;
    return 0 ;
    ......

但是我总是得到的是这样的:

看来 hdcWindow 得到的是它下面窗口的 hdc。我无法弄清楚我的 BitBlt() 调用出了什么问题。

  • 我是在 Windows 7 中完成的。

【问题讨论】:

  • 这一切都取决于所使用的hwnd。是可用的客户区吗?
  • 试试:BitBlt (hdcWindow, 0, 0, cxSource, cySource, hdcWindow, 0, 0, SRCCOPY) ;
  • 只需使用 WM_GETICON 和 DrawIcon()。
  • 如果您尝试修改 Petzold 的书 Programming Windows 5th edition 中的示例,这对我很有帮助?
  • 是的,我正在修改示例。

标签: c++ winapi gdi


【解决方案1】:
hdcClient = BeginPaint (hwnd, &ps) ;
hdcWindow = GetWindowDC (hwnd) ;

cxSource = GetSystemMetrics (SM_CXSIZEFRAME) + GetSystemMetrics (SM_CXSIZE) ;
cySource = GetSystemMetrics (SM_CYSIZEFRAME) + GetSystemMetrics (SM_CYCAPTION) ;

BitBlt (hdcClient, 0, 0, cxSource, cySource, hdcWindow, 0, 0, SRCCOPY) ;

这里,副本的目标hdcClient,它是BeginPaint 给出的句柄。但是BeginPaint 将句柄返回到客户区的上下文,这不是您想要的。您想在窗口区域的任何位置(包括滚动条/菜单等)写入,因此您可能希望目标是 hdcWindow。

【讨论】:

  • 没错,我想把它复制到我的客户区。
  • 抱歉,我误会了。所以它打印在正确的位置,但不是您想要的完整图像,是这样吗?
猜你喜欢
  • 2019-01-17
  • 1970-01-01
  • 2011-07-27
  • 2023-03-09
  • 2015-12-08
  • 2016-04-09
  • 2019-07-23
  • 1970-01-01
  • 2010-10-13
相关资源
最近更新 更多