1

大家好,我有双缓冲的问题。我不知道为什么,但我的文本没有绘制(没有双缓冲文本正在绘制)。

这是代码:

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

怎么了?

4

2 回答 2

6

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);
于 2013-07-16T08:32:13.220 回答
0

这与 GDI+ 无关。见评论@http ://www.cplusplus.com/forum/windows/35484/

于 2013-07-18T18:12:56.950 回答