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

Change the background color

Scheduled Pinned Locked Moved C / C++ / MFC
help
12 Posts 5 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.
  • M Offline
    M Offline
    m_mun
    wrote on last edited by
    #1

    Hi, I have developed a SDI application and split it into two parts. One part is simple view and another part is form view, in which i have select a dialog as child. My problem is, I can't change the background of dialog and some 'static text' controls color. I have used

    SetDialogBkColor(RGB(255, 0, 0), RGB(0, 255, 0));

    in app class. But its not working. Pls hlp. Thanks in advanced

    M 1 Reply Last reply
    0
    • M m_mun

      Hi, I have developed a SDI application and split it into two parts. One part is simple view and another part is form view, in which i have select a dialog as child. My problem is, I can't change the background of dialog and some 'static text' controls color. I have used

      SetDialogBkColor(RGB(255, 0, 0), RGB(0, 255, 0));

      in app class. But its not working. Pls hlp. Thanks in advanced

      M Offline
      M Offline
      Madhu Nair 0
      wrote on last edited by
      #2

      To change the color of a static control do that in WM_CTLCOLOR [^]message

      M 1 Reply Last reply
      0
      • M Madhu Nair 0

        To change the color of a static control do that in WM_CTLCOLOR [^]message

        M Offline
        M Offline
        m_mun
        wrote on last edited by
        #3

        Hi, Not only controls color, but also want to change the background color

        M _ 2 Replies Last reply
        0
        • M m_mun

          Hi, Not only controls color, but also want to change the background color

          M Offline
          M Offline
          Madhu Nair 0
          wrote on last edited by
          #4

          m_mun wrote:

          want to change the background color

          Create a solid brush in FormView's OnInitialUpdate m_wndbkBrush.CreateSolidBrush(RGB(0,255,0)); , and use this in OnEraseBkgnd overload of FormView.

          void CxxxFormView::OnEraseBkgnd(CDC* pDC)
          {
          CFormView::OnEraseBkgnd(pDC);
          CRect rect;
          GetClientRect(rect);
          pDC->FillRect(&rect, &m_wndbkBrush);
          return TRUE;
          }

          modified on Monday, December 7, 2009 5:09 AM

          M 1 Reply Last reply
          0
          • M Madhu Nair 0

            m_mun wrote:

            want to change the background color

            Create a solid brush in FormView's OnInitialUpdate m_wndbkBrush.CreateSolidBrush(RGB(0,255,0)); , and use this in OnEraseBkgnd overload of FormView.

            void CxxxFormView::OnEraseBkgnd(CDC* pDC)
            {
            CFormView::OnEraseBkgnd(pDC);
            CRect rect;
            GetClientRect(rect);
            pDC->FillRect(&rect, &m_wndbkBrush);
            return TRUE;
            }

            modified on Monday, December 7, 2009 5:09 AM

            M Offline
            M Offline
            m_mun
            wrote on last edited by
            #5

            Thanks, it changes the background color

            modified on Monday, December 7, 2009 5:52 AM

            M 1 Reply Last reply
            0
            • M m_mun

              Thanks, it changes the background color

              modified on Monday, December 7, 2009 5:52 AM

              M Offline
              M Offline
              m_mun
              wrote on last edited by
              #6

              Whenever i scroll down, the other portion does not changes. How can i do that? I have used

              void Cxxx::OnDraw(CDC* pDC)
              {
              CFormView::OnEraseBkgnd(pDC);
              CRect rect;
              GetClientRect(rect);
              pDC->FillRect(&rect, &m_wndbkBrush);
              return;
              }

              S D 2 Replies Last reply
              0
              • M m_mun

                Whenever i scroll down, the other portion does not changes. How can i do that? I have used

                void Cxxx::OnDraw(CDC* pDC)
                {
                CFormView::OnEraseBkgnd(pDC);
                CRect rect;
                GetClientRect(rect);
                pDC->FillRect(&rect, &m_wndbkBrush);
                return;
                }

                S Offline
                S Offline
                Sarath C
                wrote on last edited by
                #7

                Madhu already mentioned that you must do this in OnEraseBkgnd instaed of OnDraw()

                -Sarath.

                My blog - Sharing My Thoughts

                Rate the answers and close your posts if it's answered

                1 Reply Last reply
                0
                • M m_mun

                  Whenever i scroll down, the other portion does not changes. How can i do that? I have used

                  void Cxxx::OnDraw(CDC* pDC)
                  {
                  CFormView::OnEraseBkgnd(pDC);
                  CRect rect;
                  GetClientRect(rect);
                  pDC->FillRect(&rect, &m_wndbkBrush);
                  return;
                  }

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  m_mun wrote:

                  CFormView::OnEraseBkgnd(pDC);

                  You do not call this within OnDraw().

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  M 1 Reply Last reply
                  0
                  • M m_mun

                    Hi, Not only controls color, but also want to change the background color

                    _ Offline
                    _ Offline
                    _Superman_
                    wrote on last edited by
                    #9

                    As Madhu mentioned, WM_CTLCOLOR is not only for controls, but also for the dialog. When the wParam is CTLCOLOR_DLG, you can return a brush for dialog box color. Please read the documentation. It says it all.

                    «_Superman_» I love work. It gives me something to do between weekends.
                    Microsoft MVP (Visual C++)

                    1 Reply Last reply
                    0
                    • D David Crow

                      m_mun wrote:

                      CFormView::OnEraseBkgnd(pDC);

                      You do not call this within OnDraw().

                      "One man's wage rise is another man's price increase." - Harold Wilson

                      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                      M Offline
                      M Offline
                      m_mun
                      wrote on last edited by
                      #10

                      I have created a new class for form view. There is no msg handler for OnEraseBkgnd

                      D 1 Reply Last reply
                      0
                      • M m_mun

                        I have created a new class for form view. There is no msg handler for OnEraseBkgnd

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #11

                        m_mun wrote:

                        There is no msg handler for OnEraseBkgnd

                        OnEraseBkgnd() is the message handler for WM_ERASEBKGND.

                        "One man's wage rise is another man's price increase." - Harold Wilson

                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                        M 1 Reply Last reply
                        0
                        • D David Crow

                          m_mun wrote:

                          There is no msg handler for OnEraseBkgnd

                          OnEraseBkgnd() is the message handler for WM_ERASEBKGND.

                          "One man's wage rise is another man's price increase." - Harold Wilson

                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                          M Offline
                          M Offline
                          m_mun
                          wrote on last edited by
                          #12

                          Yes, but it is not displayed

                          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