In my opinion there is another way to do double buffering. Let me explain.
Let we have the following class (simplified):
Now, what happen? Windows sends WM_ERASEBKGND and then WM_PAINT (again this is simplified; I know that most of you have solid knowledge about the subject and Iím not trying to teach anybody here but get helped).
class CFlickerView : public CView
virtual void OnDraw(CDC* pDC);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
void CFlickerView::OnDraw(CDC* pDC)
CFlickerDoc* pDoc = GetDocument();
BOOL CFlickerView::OnEraseBkgnd(CDC* pDC)
return TRUE; // for now use the default handling (e.g. fill with solid color)
The OnEraseBackgroud event is triggered (if there is message map entry for it) and it should erase (e.g. fillrect) the invalidated region. Then OnDraw event is triggered and we painting here on the already erased surface (region). As a result the view flickers like hell... (I know that every one knows that, but let me finish).
So, if we do it like this:
Fill background (painting on TempDC,TempBitmap) draw the rest, copy bitmap to orgDC.
BOOL CFlickerFreeView::OnEraseBkgnd(CDC* pDC)
return TRUE; // do not erase bkgnd and tell framework we handle it
void CFlickerFreeView::OnDraw(CDC* pDC)
OldBitmap = TempDC.SelectObject(&TempBitmap);
// the painting
pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), this, rect.left, rect.top, SRCCOPY);
My idea is to patch message map, vtable or whatever needs to , save the originals and put there another proc (which will reside in dll, assuming dll is loaded by the app) like this:
The real question is how to do so? How can i find/patch vtable or message map from within dll? I've already found message map entries for OnEraseBackground and for OnDraw, patched it directly into the exe and it works, but I don't wanna modify the exe. I want to modify running image (.rsrc segment) from within the dll, but don't know how to.
//save originals and patch message map or vtable or ??? to point
TempDC=CreateTempDCAndBmp; // compatible with the original
OriginalOnDraw(&TempDC); // call original painting routine
RenderTempDC(pDC); //draw all at once
Any ideas are appreciated.