The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Airam on July 25, 2009, 06:51:40 PM

Title: Double buffering with GDI+
Post by: Airam on July 25, 2009, 06:51:40 PM
Hello...again.

I'm trying to draw a rectangle with the mouse over other draws.
This is my repaint proc:


repaint Proc hWnd:HWND
Local graphics:DWord
   Local ps:PAINTSTRUCT
   Local StaticRect:RECT

   Invoke BeginPaint, hWnd, Addr ps
   Mov StaticHDC, Eax
   Invoke GdipCreateFromHDC, StaticHDC, Addr graphics
   Invoke GdipCreateFromHWND, hWnd, Addr graphics
   Invoke GetClientRect, hWnd, Addr StaticRect
   Invoke FillRect, StaticHDC, Addr StaticRect, BoardPen
   Invoke GdipCreateFontFromLogfontA, StaticHDC, Addr logfont, Addr gpfont
        invoke drawgrid, graphics
        .If startSelection == 1
      Invoke drawZoomSelection, graphics, zoomX1, zoomY1, zoomX2, zoomY2
   .EndIf
        Invoke EndPaint, hWnd, Addr ps
   Ret
repaint EndP


The problem is that the screen starts to flick when i draw the rectangle with the mouse over the grid. How do I use double buffer with GDI+??

Thanks in advance!!


Title: Re: Double buffering with GDI+
Post by: dedndave on July 25, 2009, 07:03:55 PM
i have seen previous threads on this subject
try using the forum search function and look for "flicker"
EDIT
i think it was Hutch that had the solution
you might use advanced search and limit responses to posts by Hutch-- and get a shorter list
Title: Re: Double buffering with GDI+
Post by: Astro on July 26, 2009, 01:29:45 AM
Hi,

It appears you draw the image in memory then display the result, as opposed to drawing to the screen directly (slower).

http://www.codeproject.com/KB/GDI-plus/gdiplus.aspx

An example in C++ (only shows double-buffering part).

Best regards,
Astro.
Title: Re: Double buffering with GDI+
Post by: MichaelW on July 26, 2009, 06:28:58 AM
The example that I posted  here (http://www.masm32.com/board/index.php?topic=11284.msg83666#msg83666) does all of the drawing on a bitmap in memory, and copies the entire bitmap to the client area of the dialog each time the client area is repainted. In that example the drawing is done only once in the WM_INITDIALOG handler. There is a GeneSys mouse draw example (that uses GDI) included in the attachment  here (http://www.masm32.com/board/index.php?topic=9637.msg70478#msg70478) that does all of the drawing on a bitmap in memory, and copies the entire bitmap to the client area of the dialog each time the client area is repainted (note that the repaint is forced in the WM_MOUSEMOVE handler).