vendredi 27 février 2015

GDI Double Buffering Not Working


Vote count:

0




I am using the Bitmap_Operations() class provided here:




http://ift.tt/1BL7Djr




I am initializing it using the following:



biop = new Bitmap_Operations();
biop->Initialize_Buffers(m_hWND, 1);
biop->Create_Buffer(0);


Then I call DrawBox() from a different thread.



void DrawBox(int x, int y, int r, int g, int b, int size, int thickness)
{
// Brush style to hollow
m_LogBrush.lbStyle = BS_NULL;

// Create a logical brush and select into the context
m_hBrush = CreateBrushIndirect(&m_LogBrush);
HBRUSH hbrOldBrush = (HBRUSH)SelectObject(biop->Get_DC_Buffer(0), m_hBrush);

// Create a logical pen and select into the context
m_hPen = CreatePen(PS_SOLID, thickness, RGB(r, g, b));
HPEN hpOldPen = (HPEN)SelectObject(biop->Get_DC_Buffer(0), m_hPen);

// Draw the rectangle
Rectangle(biop->Get_DC_Buffer(0), (x - size / 2), (y - size / 2), (x + size / 2), (y + size / 2));

// Remove the object
SelectObject(biop->Get_DC_Buffer(0), hbrOldBrush); // first you must restore DC to original state
SelectObject(biop->Get_DC_Buffer(0), hpOldPen); // same here

biop->Copy_to_Screen(0);

DeleteObject(m_hBrush);
DeleteObject(m_hPen);
}


The problem is, if I remove all the "biop->Get_DC_Buffer(0)" and replace with m_hDC it draws fine but with a flicker. If I leave in the buffer calls, nothing gets drawn to the screen at all.


Am I doing something wrong?


Thanks



asked 2 mins ago







GDI Double Buffering Not Working

Aucun commentaire:

Enregistrer un commentaire