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. CEdit Control Problem - Bkgr color

CEdit Control Problem - Bkgr color

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

    The edit control has a grey background & black text, but the grey background only fills as far as the text, the rest of the edit control's background is WHITE. HOW CAN I FILL THE WHOLE BACKGROUND COLOR AS GREY. edit controls properties is set at read-only. OnCtlColor code..... HBRUSH CRSStationDefOne::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor==CTLCOLOR_EDIT) { CRSValueLoadApp* pApp = (CRSValueLoadApp*)AfxGetApp(); pDC->SetBkColor(pApp->BK_COLOR); pDC->SetTextColor(pApp->FG_COLOR); return hbr; } return NULL; } Gerry.

    L 2 Replies Last reply
    0
    • G Gerry

      The edit control has a grey background & black text, but the grey background only fills as far as the text, the rest of the edit control's background is WHITE. HOW CAN I FILL THE WHOLE BACKGROUND COLOR AS GREY. edit controls properties is set at read-only. OnCtlColor code..... HBRUSH CRSStationDefOne::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor==CTLCOLOR_EDIT) { CRSValueLoadApp* pApp = (CRSValueLoadApp*)AfxGetApp(); pDC->SetBkColor(pApp->BK_COLOR); pDC->SetTextColor(pApp->FG_COLOR); return hbr; } return NULL; } Gerry.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need to change the brush. 1) add a member variable in the dialog: CBrush m_brush; 2) init in in OnInitDialog() : m_brush.CreateSolidBrush(pApp->BK_COLOR); 3) in the destructor : m_brush.DeleteObject(); 4) modify your OnCtlColor() function : HBRUSH CRSStationDefOne::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor==CTLCOLOR_EDIT) { CRSValueLoadApp* pApp = (CRSValueLoadApp*)AfxGetApp(); pDC->SetBkColor(pApp->BK_COLOR); pDC->SetTextColor(pApp->FG_COLOR); return (HBRUSH)m_brush.GetSafeHandle(); } return hbr; // why did you return NULL here ? }

      1 Reply Last reply
      0
      • G Gerry

        The edit control has a grey background & black text, but the grey background only fills as far as the text, the rest of the edit control's background is WHITE. HOW CAN I FILL THE WHOLE BACKGROUND COLOR AS GREY. edit controls properties is set at read-only. OnCtlColor code..... HBRUSH CRSStationDefOne::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor==CTLCOLOR_EDIT) { CRSValueLoadApp* pApp = (CRSValueLoadApp*)AfxGetApp(); pDC->SetBkColor(pApp->BK_COLOR); pDC->SetTextColor(pApp->FG_COLOR); return hbr; } return NULL; } Gerry.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        You need to change the brush. 1) add a member variable in the dialog: CBrush m_brush; 2) init in in OnInitDialog() : m_brush.CreateSolidBrush(pApp->BK_COLOR); 3) in the destructor : m_brush.DeleteObject(); 4) modify your OnCtlColor() function : HBRUSH CRSStationDefOne::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor==CTLCOLOR_EDIT) { CRSValueLoadApp* pApp = (CRSValueLoadApp*)AfxGetApp(); pDC->SetBkColor(pApp->BK_COLOR); pDC->SetTextColor(pApp->FG_COLOR); return (HBRUSH)m_brush.GetSafeHandle(); } return hbr; // why did you return NULL here ? }

        G 1 Reply Last reply
        0
        • L Lost User

          You need to change the brush. 1) add a member variable in the dialog: CBrush m_brush; 2) init in in OnInitDialog() : m_brush.CreateSolidBrush(pApp->BK_COLOR); 3) in the destructor : m_brush.DeleteObject(); 4) modify your OnCtlColor() function : HBRUSH CRSStationDefOne::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor==CTLCOLOR_EDIT) { CRSValueLoadApp* pApp = (CRSValueLoadApp*)AfxGetApp(); pDC->SetBkColor(pApp->BK_COLOR); pDC->SetTextColor(pApp->FG_COLOR); return (HBRUSH)m_brush.GetSafeHandle(); } return hbr; // why did you return NULL here ? }

          G Offline
          G Offline
          Gerry
          wrote on last edited by
          #4

          Thank you Mr Anonymous, this works brilliant. We have to change lots of dialog classes, is there a place, perhaps at the app level, we could create the solidbrush & it would work for all dialogs.... Currently, we are creating the brushes in each class, this works. Again, Thanks..... Gerry.

          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