News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

redrawing graphics in a window

Started by Rainstorm, March 18, 2009, 01:37:28 PM

Previous topic - Next topic

Rainstorm

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.

MichaelW

Probably the simplest method is to redraw the graphics directly in your WM_PAINT handler using the supplied DC.
eschew obfuscation

donkey

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.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Rainstorm

hi

Thanks for the replies

Donkey, am using the plain GDI atm.

Rainstorm

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

Rainstorm

#5
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.

Jimg

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   





Rainstorm

jimq, was aware of that.. thx though.

Rainstorm

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