c++ - Win32 双缓冲绘图黑色背景

标签 c++ winapi bitblt double-buffering

用 c++ 在 win32 中做一个项目,试图对正在绘制的图像进行双重缓冲,但我得到一个黑屏,上面绘制了正确的位图。这也导致了我的 WM_MOUSEMOVE 条件,该条件将位图与光标一起拖动以不绘制位图。 paint的代码如下:paint()在WM_PAINT下的wndproc中调用,scroll为滚动条的位置,目前未使用。

int paint(HWND hWnd, HINSTANCE hInst, RECT clientRect, std::vector<Measure> *measures, int scroll)
{
int x = 90;
hdc = BeginPaint(hWnd, &ps);
hdcmem = CreateCompatibleDC(hdc);
HBITMAP hbmScreen = CreateCompatibleBitmap(hdc, clientRect.right, clientRect.bottom);
SelectObject(hdcmem,hbmScreen); 
/*these functions just create the bitmaps into hdcmem*/
drawStaff(hWnd, hInst, clientRect, x, 0);
drawKey(hWnd, hInst, clientRect, x, (*measures)[0], 0);
drawTime(hWnd, hInst, clientRect, x, (*measures)[0], 0);
drawNotes(hWnd, hInst, clientRect, measures, x);
    BitBlt(hdc, 0, 0, clientRect.right, clientRect.bottom, hdcmem, 0, 0, SRCCOPY);
ReleaseDC(hWnd, hdcmem);
return 0;
}

最佳答案

在绘制其他图形之前,您需要先用背景颜色填充位图。如果没记错的话,位图在创建时默认填充为黑色。

关于c++ - Win32 双缓冲绘图黑色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8875395/

相关文章:

c++ - 获取链接列表以打印数字

c++ - 使用字符数组和递归来反转字符串,一些线程1:EXC_BAD_ACCESS错误

c++ - 为什么 cvCopy 不会复制我的整个图像数据?

winapi - 如何使用 Windows API 重置 USB 设备?

c++ - 获取实际不存在的进程加载模块

c - 为什么屏幕截图没有使用 SelectObject 和 BitBlt 函数绘制到我的窗口上?

c++ - 启用 Aero 的 BitBlt 性能

c++ - 为什么类 B<T> 看不到父类 A<T> 的 protected 成员?

c++ - PrintWindow 导致标题栏中出现闪烁、奇怪的伪像

c++ - Bitblt,createdibsection,图像损坏