The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Rainstorm on March 18, 2009, 01:37:28 PM

Title: redrawing graphics in a window
Post by: Rainstorm on March 18, 2009, 01:37:28 PM
hi, what's the usual technique for redrawing graphics in a window ?
just copy the last state,like draw to a memory device context & then on a WM_PAINT..BitBlt & redraw it ?

thanks.
Title: Re: redrawing graphics in a window
Post by: MichaelW on March 18, 2009, 03:39:45 PM
Probably the simplest method is to redraw the graphics directly in your WM_PAINT handler using the supplied DC.
Title: Re: redrawing graphics in a window
Post by: donkey on March 18, 2009, 04:46:08 PM
Hi Rainstorm,

First a couple of assumptions, the window you want to draw in is a picture box type control, that is a static or custom control that can display bitmaps, second that you have a bitmap that you are modifying and displaying in the control. You would create a memory DC and select the bitmap into that, get the DC for the control and bitblt from the memory DC to the window DC, select the bitmap out of the memory DC and delete the DC, release the window DC. This would be done during your WM_PAINT handler, if you have a very large image you might want to only update the effected region, that is a little more complicated but can dramatically decrease drawing time. In that case you would get the update region from the WM_PAINT message, create a region in the memory DC and blt the update region to the window DC. If you are using GDI+ graphics, I think I posted a picture box routine for a GDI+ image somewhere once, probably in the GoAsm forum.
Title: Re: redrawing graphics in a window
Post by: Rainstorm on March 18, 2009, 10:47:06 PM
hi

Thanks for the replies

Donkey, am using the plain GDI atm.
Title: Re: redrawing graphics in a window
Post by: Rainstorm on March 19, 2009, 08:22:00 AM
If am using the default object I don't have to select it into a DC , just use GetCurrentObject - could you confirm if this is correct ?

some code...  trying to use the default brush with a specified color (- the region gets drawn but its white, instead of coloured)

    invoke GetDC, hwnd
    mov hdc, eax
    invoke CreateRectRgn, 50, 50, 100, 100
    mov hrgn, eax

    invoke GetCurrentObject, hdc, OBJ_BRUSH
    mov hbr, eax
    invoke SetDCBrushColor, hdc, 14786333
    mov hbrprevcol, eax
    invoke FillRgn, hdc, hrgn, hbr
    invoke SelectObject, hdc, hrgn
    invoke ReleaseDC, hwnd, hdc
Title: Re: redrawing graphics in a window
Post by: Rainstorm on March 20, 2009, 02:28:26 AM
am just trying out stuff; ..when I first draw something in the usual window, under which msg could i put it under ?
Till now I've been putting it after the UpdateWindow function. ( outside the WndProc) after creating the window
(WM_CREATE is sent  before CreateWindowEx returns.. so i suppose it won't be right to put it there)

ty

EDIT :(guess i'll just use the wm_paint msg - went full circle there ;p)
about the default DC brush color ; It seems this can't be changed without first selecting a brush into the DC (kinda like default brush attributes along with the default DC brush). it just seems to always draw in white.. which is i think the color of the default brush in the DC - anyone knows a way.. please post here.
Title: Re: redrawing graphics in a window
Post by: Jimg on March 20, 2009, 02:12:13 PM
I think you are making this too complicated.  This should work.

    invoke GetDC, hwnd
    mov hdc, eax
    invoke CreateRectRgn, 50, 50, 100, 100
    mov hrgn, eax
    invoke CreateSolidBrush,14786333
    mov hbr, eax
    invoke FillRgn, hdc, hrgn, hbr
    invoke ReleaseDC, hwnd, hdc   




Title: Re: redrawing graphics in a window
Post by: Rainstorm on March 20, 2009, 02:22:41 PM
jimq, was aware of that.. thx though.
Title: Re: redrawing graphics in a window
Post by: Rainstorm on March 20, 2009, 03:17:04 PM
about the redrawing; after whatever drawing operations, i copy the the stuff from the normal DC into a memoryDC, then on a WM_PAINT i copy the bitmap from the MemDC back to the usual DC.
It works  :U