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. CView: Change background color

CView: Change background color

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
4 Posts 4 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.
  • A Offline
    A Offline
    a_du
    wrote on last edited by
    #1

    I called setBKColor in on draw function but nothing happend, why? how to use setBKColor function and how to change the background color of the view. any one knows please tell me. thanx a lot.

    K T 2 Replies Last reply
    0
    • A a_du

      I called setBKColor in on draw function but nothing happend, why? how to use setBKColor function and how to change the background color of the view. any one knows please tell me. thanx a lot.

      K Offline
      K Offline
      khan
      wrote on last edited by
      #2

      Either use: OnDraw() { CRect rect; GetClientRect(&rect); pDC->FillSolidRect(&rect,RGB(255,0,0)); } OR: Handle the OnEraseBkGnd(): { CRect rect; GetClientRect(&rect); pDC->FillSolidRect(&rect,RGB(255,0,0)); return TRUE; } this is this.

      A 1 Reply Last reply
      0
      • K khan

        Either use: OnDraw() { CRect rect; GetClientRect(&rect); pDC->FillSolidRect(&rect,RGB(255,0,0)); } OR: Handle the OnEraseBkGnd(): { CRect rect; GetClientRect(&rect); pDC->FillSolidRect(&rect,RGB(255,0,0)); return TRUE; } this is this.

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        why the function setBKColor doen't work? how and where share i use this function. thanx a lot.

        1 Reply Last reply
        0
        • A a_du

          I called setBKColor in on draw function but nothing happend, why? how to use setBKColor function and how to change the background color of the view. any one knows please tell me. thanx a lot.

          T Offline
          T Offline
          TuPacMansur
          wrote on last edited by
          #4

          The following code is one of the ways... You would have to read the GDI to understand by SetBkColor won't work (you have to define a context first b4 u use it) void CChildView::OnPaint() { CPaintDC dc(this); // device context for painting CRect rect; GetClientRect(&rect); //Obtain the height/width of the window CBrush brush = CBrush (RGB (0, 0, 255)); //Create a blue color brush CBrush *pOldBrush = dc.SelectObject(&brush); dc.Rectangle(0, 0, rect.Width(), rect.Height()); //Fill the client area with the blue rect dc.SelectObject(pOldBrush); //restore old brush } (http://www.dvrshark.com)

          Umer Mansoor

          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