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. Setting background color of Dialog to RED

Setting background color of Dialog to RED

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

    Hi, I have taken dialog based application.When i run the application the dialog is displayed in default color.I want to change the Background color of the dialog to RED color . thanks in before jamesrocky

    N H V G 4 Replies Last reply
    0
    • R RockyJames

      Hi, I have taken dialog based application.When i run the application the dialog is displayed in default color.I want to change the Background color of the dialog to RED color . thanks in before jamesrocky

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      Handle WM_ERASEBKGND.

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

      // Save the old brush
      CBrush\* pOldBrush = pDC->SelectObject(&backBrush);
      
      // Get the current clipping boundary
      CRect rect;
      pDC->GetClipBox(&rect);
      
      // Erase the area needed
      pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),
           PATCOPY);
      
      pDC->SelectObject(pOldBrush); // Select the old brush back
      return TRUE;  // message handled
      

      }


      Nibu thomas Software Developer

      R 1 Reply Last reply
      0
      • N Nibu babu thomas

        Handle WM_ERASEBKGND.

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

        // Save the old brush
        CBrush\* pOldBrush = pDC->SelectObject(&backBrush);
        
        // Get the current clipping boundary
        CRect rect;
        pDC->GetClipBox(&rect);
        
        // Erase the area needed
        pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),
             PATCOPY);
        
        pDC->SelectObject(pOldBrush); // Select the old brush back
        return TRUE;  // message handled
        

        }


        Nibu thomas Software Developer

        R Offline
        R Offline
        RockyJames
        wrote on last edited by
        #3

        Sorry its not working, can be more clear.. thanks in before Jamesrocky

        N 1 Reply Last reply
        0
        • R RockyJames

          Sorry its not working, can be more clear.. thanks in before Jamesrocky

          N Offline
          N Offline
          Nibu babu thomas
          wrote on last edited by
          #4

          Add a message map entry

          BEGIN_MESSAGE_MAP(...,...)
          ON_WM_ERASEBKGND()
          END_MESSAGE_MAP()

          //just add the rest of the code here...


          Nibu thomas Software Developer

          1 Reply Last reply
          0
          • R RockyJames

            Hi, I have taken dialog based application.When i run the application the dialog is displayed in default color.I want to change the Background color of the dialog to RED color . thanks in before jamesrocky

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #5

            I think you can use WM_CTLCOLOR and declare a variable CBrush

            1 Reply Last reply
            0
            • R RockyJames

              Hi, I have taken dialog based application.When i run the application the dialog is displayed in default color.I want to change the Background color of the dialog to RED color . thanks in before jamesrocky

              V Offline
              V Offline
              Vinaya
              wrote on last edited by
              #6

              You can call the SetDialogBkColor() . You can have a look at this.[^] Thanks, Vini

              1 Reply Last reply
              0
              • R RockyJames

                Hi, I have taken dialog based application.When i run the application the dialog is displayed in default color.I want to change the Background color of the dialog to RED color . thanks in before jamesrocky

                G Offline
                G Offline
                Ganesh_T
                wrote on last edited by
                #7

                Hi USe this in WM_CTLCOLOR HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); hbr = CreateSolidBrush(RGB(134,179,174)); pDC->SetBkColor(RGB(255,0,255)); // Pass the RGB of RED color return hbr; Cheers "Peace of mind through Technology"

                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