C++/WinAPI GDI+ double buffering
C++/WinAPI GDI+ double buffering
大家好,我有双重缓冲的问题。我不知道为什么,但我的文本不是绘图(没有双缓冲,文本就是绘图)。
这是代码:
m_hDC = BeginPaint(m_hWnd, &m_ps);
m_graphics = new Graphics(m_hDC);
memDC = CreateCompatibleDC(m_hDC);
pMemGraphics = new Graphics(memDC);
pMemGraphics->DrawString(L"Hello world!", -1, font, PointF(100, 100), &brush);
BitBlt(m_hDC, 0, 0, 500, 200, memDC, 0, 0, SRCCOPY);
EndPaint(m_hWnd, &m_ps);
delete(pMemGraphics);
delete(m_graphics);
怎么了?
CreateCompatibleDC不会创建可在其上绘制的画布。您必须创建一个位图并将其分配给上下文。
试试这个:
m_hDC = BeginPaint(m_hWnd, &m_ps);
memDC = CreateCompatibleDC(m_hDC);
HBITMAP hBM = CreateCompatibleBitmap(m_hDC, 500, 200);
SelectObject(memDC, hBM);
// Now you can draw on memDC
// Fill with white color
RECT r;
SetRect(&r, 0, 0, 500, 200);
FillRect(memDC, &r, GetStockObject(WHITE_BRUSH));
// Draw text
::TextOut(memDC, 100, 100, "Hello world!", 12);
// Paint on window
BitBlt(m_hDC, 0, 0, 500, 200, memDC, 0, 0, SRCCOPY);
DeleteObject(hBM);
DeleteDC(memDC);
EndPaint(m_hWnd, &m_ps);
这与GDI+无关。查看评论@http://www.cplusplus.com/forum/windows/35484/
相关文章:
- C++在数学计算中将double转换为int
- 在c++中为double类型的数组创建一个unique_ptr
- vector<vector<double>> to mxArray using memcpy
- (double) 和 double() 之间的区别
- C++标准是否允许<double>在没有开销的情况下实现 std::可选
- C++ Version Of Double.longBitsToDouble
- 错误:类型"double()"和"double()"的操作数无效到二进制&quo
- 有没有办法在C++的赋值中将"char**"转换为"double"?
- 为什么 nlohmann/json 序列化 "null" 而不是在 double 上"0"?
- 使用 std::vector<double> 访问由 std::unique_ptr<double[2] 管理的数据>
- 将 std::vector<double> 从 C++ 包装到 C 以在 Swift 中使用
- 错误:无法将"<lambda(double)>"转换为"double(*)(double)"
- 如何正确将"strings"转换为"double"?
- 如何在<double>矢量中创建复杂类型的模板<T>?
- "double* grade"、"double *grade"和"double* fn()"有什么区别?
- 在不损失精度的情况下将double从C++传输到python
- 重复使用预分配的向量<复杂<double>>作为<double>长度两倍的向量
- C++ Win32 GDI double buffering
- C++/WinAPI GDI+ double buffering
- GDI+ Double Buffering