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. "Changing Editbox color"

"Changing Editbox color"

Scheduled Pinned Locked Moved C / C++ / MFC
14 Posts 6 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.
  • H harsh_2961

    Hi, When i change the background color of my dialog, along with that the color of the edit box in my dialog is changing.. but i want the editbox color to be white only.. Is there anyway to do? Is there any function like in the case of listcontrol(SetBkColor()) to get the color of Editbox to the color i want to. Harsha

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

    Default color of editbox is white but if you want to change color of editbox use of WM_CTLCOLOREDIT


    WhiteSky


    1 Reply Last reply
    0
    • P Parthi_Appu

      harsh_2961 wrote:

      When i change the background color of my dialog, along with that the color of the edit box in my dialog is changing..

      :confused: can u show the code...

      Do your Duty and Don't expect the Result

      H Offline
      H Offline
      harsh_2961
      wrote on last edited by
      #5

      I used following function HBRUSH CFileopenDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { return m_brush; } along with the line m_List.SetBkColor(RGB(255, 255, 255)); in oninitdialog(). harsha

      P 1 Reply Last reply
      0
      • P prasad_som

        harsh_2961 wrote:

        When i change the background color of my dialog, along with that the color of the edit box in my dialog is changing.

        How you have done this ?

        Prasad Notifier using ATL | Operator new[],delete[][^]

        H Offline
        H Offline
        harsh_2961
        wrote on last edited by
        #6

        I put the code in my reply just now.. please see the code.. Harsha

        P 1 Reply Last reply
        0
        • H harsh_2961

          I put the code in my reply just now.. please see the code.. Harsha

          P Offline
          P Offline
          prasad_som
          wrote on last edited by
          #7

          harsh_2961 wrote:

          please see the code

          Where ? I cannot see it .

          Prasad Notifier using ATL | Operator new[],delete[][^]

          H 1 Reply Last reply
          0
          • H harsh_2961

            Hi, When i change the background color of my dialog, along with that the color of the edit box in my dialog is changing.. but i want the editbox color to be white only.. Is there anyway to do? Is there any function like in the case of listcontrol(SetBkColor()) to get the color of Editbox to the color i want to. Harsha

            _ Offline
            _ Offline
            _AnsHUMAN_
            wrote on last edited by
            #8

            Over ride WM_ERASEBKGND and put this code over there. CPen myPen; int i =100; CRect rect ; myPen.CreatePen(PS_SOLID, 1, RGB ((i * 4),0,0)); CPen *oldPen = pDC->SelectObject(&myPen) ; GetClientRect(&rect); for(i = 0 ; i <= rect.bottom;) { pDC->MoveTo(0, i); pDC->LineTo(rect.right, i); pDC->SelectObject (&myPen); } pDC->SelectObject(oldPen) ; return TRUE ; The edit box would not be painted to match the dialog back color and would show as white. See if this helps _AnShUmAn_ -- modified at 4:55 Wednesday 14th March, 2007

            1 Reply Last reply
            0
            • P prasad_som

              harsh_2961 wrote:

              please see the code

              Where ? I cannot see it .

              Prasad Notifier using ATL | Operator new[],delete[][^]

              H Offline
              H Offline
              harsh_2961
              wrote on last edited by
              #9

              I used following function HBRUSH CFileopenDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { return m_brush; } along with the line m_List.SetBkColor(RGB(255, 255, 255)); in oninitdialog(). Harsha

              P 1 Reply Last reply
              0
              • H harsh_2961

                I used following function HBRUSH CFileopenDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { return m_brush; } along with the line m_List.SetBkColor(RGB(255, 255, 255)); in oninitdialog(). harsha

                P Offline
                P Offline
                Parthi_Appu
                wrote on last edited by
                #10

                harsh_2961 wrote:

                along with the line m_List.SetBkColor(RGB(255, 255, 255)); in oninitdialog().

                Hope the m_List is your CEdit control.

                harsh_2961 wrote:

                HBRUSH CFileopenDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { return m_brush; }

                Instead of simply returning m_brush(hope this the brush to paint the dialog background). Try this,

                CFileopenDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
                {
                HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
                if (CTLCOLOR_EDIT != nCtlColor)
                return m_brush;
                return hbr;
                }

                The above change the background color for all the controls in the dialog except for the CEdit controls. If you want to change the color only to the dialog then change the 'if' condition as below

                if (CTLCOLOR_DLG == nCtlColor)

                Do your Duty and Don't expect the Result

                H 1 Reply Last reply
                0
                • P Parthi_Appu

                  harsh_2961 wrote:

                  along with the line m_List.SetBkColor(RGB(255, 255, 255)); in oninitdialog().

                  Hope the m_List is your CEdit control.

                  harsh_2961 wrote:

                  HBRUSH CFileopenDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { return m_brush; }

                  Instead of simply returning m_brush(hope this the brush to paint the dialog background). Try this,

                  CFileopenDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
                  {
                  HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
                  if (CTLCOLOR_EDIT != nCtlColor)
                  return m_brush;
                  return hbr;
                  }

                  The above change the background color for all the controls in the dialog except for the CEdit controls. If you want to change the color only to the dialog then change the 'if' condition as below

                  if (CTLCOLOR_DLG == nCtlColor)

                  Do your Duty and Don't expect the Result

                  H Offline
                  H Offline
                  harsh_2961
                  wrote on last edited by
                  #11

                  Thanks a lot ... its perfectly working :) Harsha

                  1 Reply Last reply
                  0
                  • H harsh_2961

                    I used following function HBRUSH CFileopenDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { return m_brush; } along with the line m_List.SetBkColor(RGB(255, 255, 255)); in oninitdialog(). Harsha

                    P Offline
                    P Offline
                    prasad_som
                    wrote on last edited by
                    #12

                    I'm not sure, how you have done it, but modify your code to,

                    CFileopenDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
                    {
                    return m_brush;
                    }

                    To skip edit control painting do this,
                    HBRUSH CFileopenDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
                    {
                    m_brush= CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
                    if (nCtlColor == CTLCOLOR_EDIT)
                    {
                    return brush
                    }
                    else
                    {
                    //do your customized painting
                    }

                    return m_brush;
                    }

                    Prasad Notifier using ATL | Operator new[],delete[][^]

                    1 Reply Last reply
                    0
                    • H harsh_2961

                      Hi, When i change the background color of my dialog, along with that the color of the edit box in my dialog is changing.. but i want the editbox color to be white only.. Is there anyway to do? Is there any function like in the case of listcontrol(SetBkColor()) to get the color of Editbox to the color i want to. Harsha

                      T Offline
                      T Offline
                      ThatsAlok
                      wrote on last edited by
                      #13

                      harsh_2961 wrote:

                      When i change the background color of my dialog, along with that the color of the edit box in my dialog is changing.. but i want the editbox color to be white only..

                      HBRUSH CFileopenDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) {  HBRUSH OrgBrush=CreateSolidBrush(RGB(255,255,255)); // make it white   if(pWnd->GetSafeHwnd() == GetDlgItem(IDC_EDIT1)->GetSafeHwnd()) {   return OrgBrush; } return m_brush; }

                      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                      cheers, Alok Gupta Global Interface Table: An Easy Way to Marshal an Interface Pointer[new] VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

                      P 1 Reply Last reply
                      0
                      • T ThatsAlok

                        harsh_2961 wrote:

                        When i change the background color of my dialog, along with that the color of the edit box in my dialog is changing.. but i want the editbox color to be white only..

                        HBRUSH CFileopenDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) {  HBRUSH OrgBrush=CreateSolidBrush(RGB(255,255,255)); // make it white   if(pWnd->GetSafeHwnd() == GetDlgItem(IDC_EDIT1)->GetSafeHwnd()) {   return OrgBrush; } return m_brush; }

                        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                        cheers, Alok Gupta Global Interface Table: An Easy Way to Marshal an Interface Pointer[new] VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

                        P Offline
                        P Offline
                        prasad_som
                        wrote on last edited by
                        #14

                        ThatsAlok wrote:

                        if(pWnd->GetSafeHwnd() == GetDlgItem(IDC_EDIT1)->GetSafeHwnd())

                        if (pWnd->GetDlgCtrlID() == IDC_EDIT1) would be better.

                        Prasad Notifier using ATL | Operator new[],delete[][^]

                        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