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. How to change editbox's background color when it is set to read-only?

How to change editbox's background color when it is set to read-only?

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

    When I set the editbox to read-only, its backgroud color will be gray. Can I set it to another color? Thanks in advance.

    C A 2 Replies Last reply
    0
    • V Vincent Ye

      When I set the editbox to read-only, its backgroud color will be gray. Can I set it to another color? Thanks in advance.

      C Offline
      C Offline
      Carlos Antollini
      wrote on last edited by
      #2

      Try to chenge the backcolor with the Erase Background message.... Best Regards Carlos Antollini. Sonork ID 100.10529 cantollini

      1 Reply Last reply
      0
      • V Vincent Ye

        When I set the editbox to read-only, its backgroud color will be gray. Can I set it to another color? Thanks in advance.

        A Offline
        A Offline
        adamUK
        wrote on last edited by
        #3

        You can!! :) handle the WM_CTLCOLOR message and check if the handle of the window passed to the handler function is equal to the handle of the editbox whose colour you want to change. Then set the handle hbr to the brush you want to use as your background. Call SetBkColor() to change the background colour used when painting your text. Look up WM_CTLCOLOR in MSDN!! hope this helps Adam. "I spent a lot of my money on booze, birds and fast cars. The rest I just squandered" George Best.

        V 1 Reply Last reply
        0
        • A adamUK

          You can!! :) handle the WM_CTLCOLOR message and check if the handle of the window passed to the handler function is equal to the handle of the editbox whose colour you want to change. Then set the handle hbr to the brush you want to use as your background. Call SetBkColor() to change the background colour used when painting your text. Look up WM_CTLCOLOR in MSDN!! hope this helps Adam. "I spent a lot of my money on booze, birds and fast cars. The rest I just squandered" George Best.

          V Offline
          V Offline
          Vincent Ye
          wrote on last edited by
          #4

          I have tried to handle the WM_CTLCOLOR message, but failed. When the editbox is set to read-only, it will not send the WM_CTLCOLOR to its parent window. Anyway, thanks a lot.

          A 1 Reply Last reply
          0
          • V Vincent Ye

            I have tried to handle the WM_CTLCOLOR message, but failed. When the editbox is set to read-only, it will not send the WM_CTLCOLOR to its parent window. Anyway, thanks a lot.

            A Offline
            A Offline
            adamUK
            wrote on last edited by
            #5

            Hmm.. I am doing the same... the following code paints a white background in IDC_USER and IDC_KEY which are read only (I didn't want them to be gray) and paints everything else with a blue background. They are Enabled though (i.e. EnableWindow(TRUE)). HBRUSH CCncloginDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); HWND hWnd=pWnd->GetSafeHwnd(); // TODO: Change any attributes of the DC here if(nCtlColor==CTLCOLOR_EDIT || hWnd==GetDlgItem(IDC_USER)->GetSafeHwnd() || hWnd==GetDlgItem(IDC_KEY)->GetSafeHwnd()) { pDC->SetBkColor(RGB(255,255,255)); hbr=(HBRUSH)m_brBrush; } else { pDC->SetBkColor(RGB(128,128,200)); hbr=(HBRUSH)m_brBrush2; } // TODO: Return a different brush if the default is not desired return hbr; } Sounds mysterious! If you work out what's up then post it. I would be interested to hear what it was. :) Adam. "I spent a lot of my money on booze, birds and fast cars. The rest I just squandered" George Best.

            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