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

Change color of the Form

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 3 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.
  • J Offline
    J Offline
    JekYu
    wrote on last edited by
    #1

    Hi.. I'm using a project whose baseclass is CFORMVIEW.. my question is HOW DO YOU CHANGE the COLOR of the FORM??? Thanks...

    A R 2 Replies Last reply
    0
    • J JekYu

      Hi.. I'm using a project whose baseclass is CFORMVIEW.. my question is HOW DO YOU CHANGE the COLOR of the FORM??? Thanks...

      A Offline
      A Offline
      Alex Taylor
      wrote on last edited by
      #2

      OnEraseBackground. Draw the colour you want here instead. Alex

      J 1 Reply Last reply
      0
      • A Alex Taylor

        OnEraseBackground. Draw the colour you want here instead. Alex

        J Offline
        J Offline
        JekYu
        wrote on last edited by
        #3

        Hi ... Sorry to ask you once again ...but I don't seem to understand your response. Is this OnEraseBackground a windows message handler .. and where should I add such windows message handler (I only saw WM_ERASEBKGND on the CMainFrame)? And what's the command to change the color of the Form? Please, elucidate. Thanks for the help. =)

        A 1 Reply Last reply
        0
        • J JekYu

          Hi ... Sorry to ask you once again ...but I don't seem to understand your response. Is this OnEraseBackground a windows message handler .. and where should I add such windows message handler (I only saw WM_ERASEBKGND on the CMainFrame)? And what's the command to change the color of the Form? Please, elucidate. Thanks for the help. =)

          A Offline
          A Offline
          Alex Taylor
          wrote on last edited by
          #4

          I've just had a look, and the view *does* have WM_ERASEBKGND. There is no command, this is called whenever the area is erased and you will need to draw the background. Something like this:

          CRect rc;
          GetClientRect(&rc);

          pDC->FillSolidRect(&rc, RGB(255,0,0));
          //Do not call base method

          Alex

          J 1 Reply Last reply
          0
          • A Alex Taylor

            I've just had a look, and the view *does* have WM_ERASEBKGND. There is no command, this is called whenever the area is erased and you will need to draw the background. Something like this:

            CRect rc;
            GetClientRect(&rc);

            pDC->FillSolidRect(&rc, RGB(255,0,0));
            //Do not call base method

            Alex

            J Offline
            J Offline
            JekYu
            wrote on last edited by
            #5

            Oh.. didn't see that there was WM_ERASEBKGND.. coz the filter messages was to the default class:VIEW class instead of the window or child window.. so i didn't see it... alex, thanks a lot...ciao...

            1 Reply Last reply
            0
            • J JekYu

              Hi.. I'm using a project whose baseclass is CFORMVIEW.. my question is HOW DO YOU CHANGE the COLOR of the FORM??? Thanks...

              R Offline
              R Offline
              Richard Stringer
              wrote on last edited by
              #6

              Erasebackground will not completly solve your problem nor do I think it is the prefered method. Usesomething like this: void CMainView::OnPaint() { CMainFrame* pFrame; CPaintDC dc(this); // device context for painting pFrame = (CMainFrame*)GetParentFrame(); CString s="Printing Library Demo Program"; pFrame->SetWindowText(s); RECT rc; CBrush cBr(RGB(255,255,0)); GetClientRect(&rc); dc.FillRect(&rc, &cBr); } then to solve the control background problem use this: HBRUSH CMainView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor); if(nCtlColor==CTLCOLOR_STATIC) { HBRUSH hbr2=CreateSolidBrush(RGB(255,255,0)); pDC->SetBkMode(TRANSPARENT); return hbr2; } return hbr; } Class wizard will make both overrides for you Richard ISS Software Dallas Texas

              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