dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: How to avoid losing graphical changes when window is minimized and then restored?

  1. #1
    Join Date
    Dec 2008
    Posts
    1

    Question How to avoid losing graphical changes when window is minimized and then restored?

    Hi. I'm starting with GDI in VC++ 6.0 and I'd be very grateful if you could lend me a hand with this. I have done a very simple application in which I draw with the mouse in the window. I catch the DC in the OnMouseMove event, then draw lines from point 'a' to point 'b' and then ReleaseDC. It works good when tested, but when I minimize the window and restore it again from the Windows Taskbar, what I drew is lost. What can I do to prevent this erasing?

    Thank you in advance.

  2. #2
    Join Date
    Jan 2008
    Posts
    178

    Re: How to avoid losing graphical changes when window is minimized and then restored?

    Read MSDN and the Petzold for WM_PAINT.
    It's the Base of the Base.

  3. #3
    Join Date
    Apr 1999
    Posts
    3,585

    Re: How to avoid losing graphical changes when window is minimized and then restored?

    Your application is not "erasing". It is actually not remembering to draw. Most rendering to the screen happens in the OnDraw () event if you have a Doc/View type application architecture. The act of minimizing and restoring the application will force several events to occur when the application is activated. The least of which is a call to erase the background of the screen and a request to re-draw it. If you are not storing the state of the screen (ie. in a bitmap), or, re-drawing the screen when the OnDraw event occurs, the screen will appear just as you've indicated. You may want to research how the MFC architecture works. For example, take a look here.
    Gort...Klaatu, Barada Nikto!

  4. #4
    Join Date
    Nov 2007
    Posts
    613

    Re: How to avoid losing graphical changes when window is minimized and then restored?

    The graphic appearance of a window is never memorized (well, almost never).

    It is your responsibility to provide code to redraw the window each time it needs to be repainted (minimized, resized, obstructed by other windows, ...)

    The code to (re)draw the window is stored in the WM_PAINT message handler. That handler is called ever time the window needs redraw. If there is a specific sequence of code to draw something in the WM_PAINT handler that thing will be redrawn every time. If it's not there, the window will "forget" to redraw it.

    If the user has drawn a curve in the window, store the points defining the mouse positions somewhere then write code in the WM_PAINT handler to (re)draw that curve using the stored information about the points.

    Another approach is to store all the graphics in a memory dc and use WM_PAINT just to copy that graphics on the screen.

    The most important thing to remember: only the drawing generated by the code in the WM_PAINT handler will be remembered, everything else will vanish on resize, minimization or obstruction by other windows.
    Last edited by srelu; December 4th, 2008 at 09:12 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)