Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. A Black View

A Black View

Scheduled Pinned Locked Moved C / C++ / MFC
graphicstutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bilal Naveed
    wrote on last edited by
    #1

    How can I set the background color of a CView derived class(to black for example), without doing something silly like drawing a view-spanning rectangle in OnDraw() :) cheers Bilal

    T 1 Reply Last reply
    0
    • B Bilal Naveed

      How can I set the background color of a CView derived class(to black for example), without doing something silly like drawing a view-spanning rectangle in OnDraw() :) cheers Bilal

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      Handle the WM_ERASEBKGND message. Inside the handler, use PatBlt to fill the window with desired color.

      BOOL CYourView::OnEraseBkgnd(CDC* pDC)
      {
      // Set brush to desired background color
      CBrush backBrush(RGB(0, 0, 0));

      // Save old brush
      CBrush* pOldBrush = pDC->SelectObject(&backBrush);

      CRect rc;
      pDC->GetClipBox(&rc); // Erase the area needed
      pDC->PatBlt(rc.left, rc.top, rc.Width(), rc.Height(), PATCOPY);
      pDC->SelectObject(pOldBrush);
      return TRUE;
      }

      Tomasz Sowinski -- http://www.shooltz.com.pl

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups