Click to See Complete Forum and Search --> : Persist drawing on form
deostroll
July 1st, 2008, 04:40 AM
I am working on a 2d graph project. When is the best time I can try to draw the axes on the form for the first time. And if I draw the axes how can I persist it - if I move the window or minimize it and then restore it, what ever is drawn on the form disappears. How can I persist this?
Marc G
July 1st, 2008, 09:29 AM
You need to draw everything in OnPaint. That way when you move a window over your window, it will be repainted giving the illusion it is persistant.
deostroll
July 2nd, 2008, 12:19 AM
On WM_PAINT, you mean? But if I have plotted a function, it means I'd have to redraw the whole thing once again...
I don't know when WM_PAINT gets first called!
ProgramArtist
July 2nd, 2008, 02:03 AM
On WM_PAINT, you mean? But if I have plotted a function, it means I'd have to redraw the whole thing once again...
I don't know when WM_PAINT gets first called!
All about WM_PAINT: Here in MSDN (http://msdn.microsoft.com/de-de/library/ms534870(en-us).aspx)
And yes: In a typical windows application all drawing is implemented in response to the WM_PAINT message.
Ok, there are cases where some things could be pre-rendered somewhere else... But anyway: I've done the drawing in OnPaint().
With regards
Programartist
DreamShore
July 2nd, 2008, 05:01 AM
Unless your system is Vista and areo is on, you are not drawing on the window as you may think, instead, you are drawing on the screen. Like when you want to "move" something on a piece of paper, you need erase it and draw it again. System won't keep the visual containt of a window, but you can maintain it yourself. Just draw it on a bitmap in the memory, and draw the bitmap when handling WM_PAINT.
deostroll
July 2nd, 2008, 05:19 AM
What is the api I need to store a bitmap to memory?
DreamShore
July 2nd, 2008, 05:38 AM
Find memory DC in msdn documents.
It is indexed as "memory device context [Win32]".
Marc G
July 3rd, 2008, 08:40 AM
Actually, you'll need to create a memory bitmap, for example by using CreateCompatibleBitmap (http://msdn.microsoft.com/en-us/library/ms532287(VS.85).aspx). This is the actual object that will really store your bitmap. However, before you can draw anything on that bitmap, you need to create a memory device context using for example CreateCompatibleDC (http://msdn.microsoft.com/en-us/library/ms533239(VS.85).aspx). Then select your bitmap into your device context and then you can start drawing on it.
Then when handling WM_PAINT you can basically just bitblt your memory device context to the screen. To get more information regarding this topic, it might be helpful to search for articles concerning double buffering since they also use memory bitmaps to prevent flickering.
codeguru.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved.