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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Setting Background Color

Setting Background Color

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
5 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.
  • L Offline
    L Offline
    lostris
    wrote on last edited by
    #1

    HI everybody! I need to know how to set the background color of a view. I have tried using the 'SetBkColor(COLORREF color)' function but I can't get it to work. I called the following line in the Draw function in class CView. pDC->SetBkColor(COLORREF color); And the background color remains white. Can anybody tell me what to do? _Lostris. . .

    E M M 3 Replies Last reply
    0
    • L lostris

      HI everybody! I need to know how to set the background color of a view. I have tried using the 'SetBkColor(COLORREF color)' function but I can't get it to work. I called the following line in the Draw function in class CView. pDC->SetBkColor(COLORREF color); And the background color remains white. Can anybody tell me what to do? _Lostris. . .

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      you need to "paint" it. CDC::FillRect or something similir.


      Maximilien Lincourt Your Head A Splode - Strong Bad

      L 1 Reply Last reply
      0
      • L lostris

        HI everybody! I need to know how to set the background color of a view. I have tried using the 'SetBkColor(COLORREF color)' function but I can't get it to work. I called the following line in the Draw function in class CView. pDC->SetBkColor(COLORREF color); And the background color remains white. Can anybody tell me what to do? _Lostris. . .

        E Offline
        E Offline
        Edwin Brunner
        wrote on last edited by
        #3

        MSDN says: "Sets the current background color to the specified color. If the background mode is OPAQUE, the system uses the background color to fill the gaps in styled lines, the gaps between hatched lines in brushes, and the background in character cells. The system also uses the background color when converting bitmaps between color and monochrome device contexts." So, if you don't write or draw anything, you won't see the desired color. My suggestion for the 'OnDraw(..)' function: CRect rect; GetClientRect(rect); pDC->FillSolidRect(rect, RGB(255,0,0)); There might be other solutions.

        1 Reply Last reply
        0
        • L lostris

          HI everybody! I need to know how to set the background color of a view. I have tried using the 'SetBkColor(COLORREF color)' function but I can't get it to work. I called the following line in the Draw function in class CView. pDC->SetBkColor(COLORREF color); And the background color remains white. Can anybody tell me what to do? _Lostris. . .

          M Offline
          M Offline
          Mahendra_786
          wrote on last edited by
          #4

          In a Win32 application you can set the hbrBackground member of the window class structure typically in "MyRegisterClass". wcex.hbrBackground = CreateSolidBrush(RGB(255, 0, 0)); // This makes the window red In MFC you can do something similar in PreCreateWindow. Due Regards Mahendra

          1 Reply Last reply
          0
          • M Maximilien

            you need to "paint" it. CDC::FillRect or something similir.


            Maximilien Lincourt Your Head A Splode - Strong Bad

            L Offline
            L Offline
            lostris
            wrote on last edited by
            #5

            FillRect has seemed to work just fine at first, but when I have to scroll the image, the part of the view that was not visible at the start is still white. Do you have any other suggestions? Thanx _Lostris.

            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