Re: Need Help Fixing GDI Leaks

From: Scott McPhillips [MVP] (org-dot-mvps-at-scottmcp)
Date: 02/26/05


Date: Fri, 25 Feb 2005 19:43:54 -0500

Phillip N Rounds wrote:
> The reason OnDraw() gets called throughout this app is that the app
> controls an external piece of lab equipment ( actually 3 ), and collects &
> presents data from one of the machines. Each of the machines, and of course
> the user, can instigate a need to redraw one of the views, with one machine
> instigating a need to redraw the view every second. The OnDraw() function
> switches on some data in the associated Doc to determine if the entire view
> needs to be redrawn, or simply has to add the next line segment(s) in the
> graph. What I was trying to do in all of this was to minimize the amount of
> work involved in each update to the view.
>
> So, the real reason I am responding except to say thanks is that it is
> entirely possible that I have taken the wrong approach to this and I wanted
> to understand your response better. I really can't just repaint the entire
> for each new data point, that would be too graphics intensive. With this
> further input, do you still think I have taken the wrong approach?

You are still breaking Rule 1 of Windows painting.

Have you experimented with covering and then uncovering parts of your
view with some other program's window? What happens, for example, if
you bring up the Windows clock and move that window around? According
to your description, your view would not properly repaint when uncovered.

In other words, your doc variables do not know enough to determine how
much of the view needs to be redrawn.

The solution is to call the view Invalidate() to force the whole view to
repaint, or you can call InvalidateRect() if you want to request only a
partial repaint. To reduce or avoid unnecessary repainting the OnDraw
code can call GetClipBox to determine how much of the view to redraw.
GetClipBox gives you the union of the area you invalidated and the area
that Windows may have invalidated.

-- 
Scott McPhillips [VC++ MVP]


Relevant Pages

  • Re: Need Help Fixing GDI Leaks
    ... > presents data from one of the machines. ... > instigating a need to redraw the view every second. ... You are still breaking Rule 1 of Windows painting. ... your view would not properly repaint when uncovered. ...
    (microsoft.public.vc.mfc.docview)
  • Re: Need Help Fixing GDI Leaks
    ... > presents data from one of the machines. ... > instigating a need to redraw the view every second. ... You are still breaking Rule 1 of Windows painting. ... your view would not properly repaint when uncovered. ...
    (microsoft.public.vc.mfc)
  • Re: repainting own panel-component
    ... When a resize operation ... Windows sends a wm_Sizing message. ... >stripes remains constant and they get thicker when the control grows, ... ClientRect then one might as well check that, and repaint the lot, ...
    (comp.lang.pascal.delphi.misc)
  • Re: redraw shape after shapedata change
    ... Dim mastershape As Visio.Master ... So how can I redraw just one shape? ... the Visio instance will not refresh the screen (repaint drawing windows) as documents change or when they become obscured by other windows. ...
    (microsoft.public.visio.general)
  • Lockwindowupdate
    ... I have written an app which has, as it's main screen, a form set to ... maximized with no border. ... When the app is shutdown several windows do not ... fully redraw themselves. ...
    (microsoft.public.vb.winapi)

Loading