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. Question about CEdit

Question about CEdit

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

    Hi. I set my dialog color to black with GetStockObject( BLACK_BRUSH );, then I put edit control with different 'BkColor' CDC *pEditDC=m_edtInfo.GetDC(); pEditDC->SetBkColor(RGB(230,251,251)); pEditDC->SetTextColor(RGB(255,255,255)); ReleaseDC(pEditDC); When my dialog shows at first (before my edit control has no input string) I don't even see it (all dialog is black)! When I populate edit control m_edtInfo.SetWindowText('some text') text is displayed and edit ctrl's BkColor is shown but only behind the text not on all edit ctrl rectangle.why? How to get all edit ctrl's region being filled with BkColour, even at first? Thanks! P.S. My apology for my language.

    J N J 3 Replies Last reply
    0
    • J josip cagalj

      Hi. I set my dialog color to black with GetStockObject( BLACK_BRUSH );, then I put edit control with different 'BkColor' CDC *pEditDC=m_edtInfo.GetDC(); pEditDC->SetBkColor(RGB(230,251,251)); pEditDC->SetTextColor(RGB(255,255,255)); ReleaseDC(pEditDC); When my dialog shows at first (before my edit control has no input string) I don't even see it (all dialog is black)! When I populate edit control m_edtInfo.SetWindowText('some text') text is displayed and edit ctrl's BkColor is shown but only behind the text not on all edit ctrl rectangle.why? How to get all edit ctrl's region being filled with BkColour, even at first? Thanks! P.S. My apology for my language.

      J Offline
      J Offline
      Jason Teagle
      wrote on last edited by
      #2

      Trying to set the back colour like this will not work. You need to override WM_CTLCOLOR in the dialog class to change the colours of the dialog itself and its controls.

      J 1 Reply Last reply
      0
      • J josip cagalj

        Hi. I set my dialog color to black with GetStockObject( BLACK_BRUSH );, then I put edit control with different 'BkColor' CDC *pEditDC=m_edtInfo.GetDC(); pEditDC->SetBkColor(RGB(230,251,251)); pEditDC->SetTextColor(RGB(255,255,255)); ReleaseDC(pEditDC); When my dialog shows at first (before my edit control has no input string) I don't even see it (all dialog is black)! When I populate edit control m_edtInfo.SetWindowText('some text') text is displayed and edit ctrl's BkColor is shown but only behind the text not on all edit ctrl rectangle.why? How to get all edit ctrl's region being filled with BkColour, even at first? Thanks! P.S. My apology for my language.

        N Offline
        N Offline
        Nelek
        wrote on last edited by
        #3

        You can get the whole rectangle with void CEdit::GetRect( LPRECT lpRect ) const; and insteads of set the background of the CEdit, do it with the lpRect. Then use the CDialog::OnInitDialog (); to make your changes and... remember to change the background of the dialog before changing/filling the edits

        Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you ;)

        1 Reply Last reply
        0
        • J josip cagalj

          Hi. I set my dialog color to black with GetStockObject( BLACK_BRUSH );, then I put edit control with different 'BkColor' CDC *pEditDC=m_edtInfo.GetDC(); pEditDC->SetBkColor(RGB(230,251,251)); pEditDC->SetTextColor(RGB(255,255,255)); ReleaseDC(pEditDC); When my dialog shows at first (before my edit control has no input string) I don't even see it (all dialog is black)! When I populate edit control m_edtInfo.SetWindowText('some text') text is displayed and edit ctrl's BkColor is shown but only behind the text not on all edit ctrl rectangle.why? How to get all edit ctrl's region being filled with BkColour, even at first? Thanks! P.S. My apology for my language.

          J Offline
          J Offline
          jhwurmbach
          wrote on last edited by
          #4

          Easiest would be if you look into one of the controls shown in the Editcontrol-section of codeproject[^]. You will find a lot of source code to look how it is done. Chris Losinger has made a coloring Editcontrol I use.


          Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
          George Orwell, "Keep the Aspidistra Flying", Opening words

          1 Reply Last reply
          0
          • J Jason Teagle

            Trying to set the back colour like this will not work. You need to override WM_CTLCOLOR in the dialog class to change the colours of the dialog itself and its controls.

            J Offline
            J Offline
            josip cagalj
            wrote on last edited by
            #5

            Thanks for replay. I'm already overriding that: HBRUSH CDialList::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if( nCtlColor == CTLCOLOR_DLG ) { m_myHbr = (HBRUSH) GetStockObject( BLACK_BRUSH ); } return m_myHbr; } for setting my dialog color to black! You are saying I can put more code on it and deal with color for my edit ctrl. Ok I put additional line code (if statement): if( nCtlColor == CTLCOLOR_EDIT ) but can you tell me what to use to set color to RGB value and not to use GetStockObject? Thanks!

            J 1 Reply Last reply
            0
            • J josip cagalj

              Thanks for replay. I'm already overriding that: HBRUSH CDialList::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if( nCtlColor == CTLCOLOR_DLG ) { m_myHbr = (HBRUSH) GetStockObject( BLACK_BRUSH ); } return m_myHbr; } for setting my dialog color to black! You are saying I can put more code on it and deal with color for my edit ctrl. Ok I put additional line code (if statement): if( nCtlColor == CTLCOLOR_EDIT ) but can you tell me what to use to set color to RGB value and not to use GetStockObject? Thanks!

              J Offline
              J Offline
              josip cagalj
              wrote on last edited by
              #6

              This is how it looks now: HBRUSH CDialList::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if( nCtlColor == CTLCOLOR_DLG )//for dialog { m_myHbr = (HBRUSH) GetStockObject( BLACK_BRUSH ); } if( nCtlColor == CTLCOLOR_EDIT )//for edit ctrl { CDC *pEditDC=m_edtInfo.GetDC(); //set text to black SetTextColor(*pEditDC,RGB(255,255,255)); //set background to RGB(230,251,251) m_myHbr = (HBRUSH) pEditDC->SetBkColor(RGB(230,251,251)); ReleaseDC(pEditDC); } return m_myHbr; } But unfortunate still doesn't work!?!

              M 1 Reply Last reply
              0
              • J josip cagalj

                This is how it looks now: HBRUSH CDialList::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if( nCtlColor == CTLCOLOR_DLG )//for dialog { m_myHbr = (HBRUSH) GetStockObject( BLACK_BRUSH ); } if( nCtlColor == CTLCOLOR_EDIT )//for edit ctrl { CDC *pEditDC=m_edtInfo.GetDC(); //set text to black SetTextColor(*pEditDC,RGB(255,255,255)); //set background to RGB(230,251,251) m_myHbr = (HBRUSH) pEditDC->SetBkColor(RGB(230,251,251)); ReleaseDC(pEditDC); } return m_myHbr; } But unfortunate still doesn't work!?!

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                You shouldn't be getting a DC for the control. Everything you need is passed to your OnCtlColor() method. You should use the passed DC. Mark

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                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