Thread: Clearing the Windows Device Context

  1. #1
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195

    Clearing the Windows Device Context

    What is the best way to clear the screen before redrawing if using a Windows Device Context as your drawing surface

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    Use the ClearScreen() fuction that is part of whatever API your using.

  3. #3
    ---
    Join Date
    May 2004
    Posts
    1,379
    Can't you FillRect() or something like that?

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    If you are filling white or black you can use those flags in BitBlt as a quick fill. Otherwise, you can use this as a faster alternative to FillRect:

    Code:
    void PaintRect(HDC hdc, RECT *rect, COLORREF colour)
    {
      COLORREF oldcr = SetBkColor(hdc, colour);
      ExtTextOut(hdc, 0, 0, ETO_OPAQUE, rect, "", 0, 0);
      SetBkColor(hdc, oldcr);
    }
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  5. #5
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    yea fillrect works thanks sand man

  6. #6
    ---
    Join Date
    May 2004
    Posts
    1,379
    Quote Originally Posted by loopshot
    yea fillrect works thanks sand man
    Nice guess wasn't it?

  7. #7
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    HA, here is one better than both of your suggestins
    Code:
    BOOL FloodFill(
      HDC hdc,          // handle to DC
      int nXStart,      // starting x-coordinate
      int nYStart,      // starting y-coordinate
      COLORREF crFill   // fill color
    );
    but thank you all for the help guys

  8. #8
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    FloodFill() is not better than FillRect().

    FloodFill is more for filling areas with borders than it is for large areas. FillRect() simply creates a colored square the size of the rect specified. This is a much faster process. FloodFill() is a somewhat complex function and I wouldn't use it for what you want to do.

  9. #9
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    Thanks budda

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Device Driver: sysfs confusion
    By filker0 in forum Linux Programming
    Replies: 0
    Last Post: 12-02-2005, 11:36 AM
  2. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM
  3. How come this only works in Windows nt/2000?
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 08-30-2002, 06:54 PM
  4. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM