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. color

color

Scheduled Pinned Locked Moved C / C++ / MFC
help
12 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.
  • Y yogendra kaushik

    hi all plz help me i want to change color of a particular control on which text is displayed but problem is that when i try folloeing code it will change color only of the text's background but not of all control plz tel me code for this HBRUSH CAfterone::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Change any attributes of the DC here pDC->SetBkColor(RGB(0, 0, 0)); // TODO: Return a different brush if the default is not desired return hbr; } Please mail me

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

    CPaintDC dc(this); // device context for painting dc.SetTextColor(RGB(0,0,200)); dc.TextOutW(10,10,_T("test"),4); and Here[^]_**


    **_

    whitesky


    1 Reply Last reply
    0
    • Y yogendra kaushik

      hi all plz help me i want to change color of a particular control on which text is displayed but problem is that when i try folloeing code it will change color only of the text's background but not of all control plz tel me code for this HBRUSH CAfterone::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Change any attributes of the DC here pDC->SetBkColor(RGB(0, 0, 0)); // TODO: Return a different brush if the default is not desired return hbr; } Please mail me

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

      HBRUSH CAfterone::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Change any attributes of the DC here if(pWnd->GetDlgCtrlID()==/*Put your control id Here ex IDC_EDIT1*/) // return your color brush here // TODO: Return a different brush if the default is not desired return hbr; } Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_

      Y 1 Reply Last reply
      0
      • Y yogendra kaushik

        hi all plz help me i want to change color of a particular control on which text is displayed but problem is that when i try folloeing code it will change color only of the text's background but not of all control plz tel me code for this HBRUSH CAfterone::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Change any attributes of the DC here pDC->SetBkColor(RGB(0, 0, 0)); // TODO: Return a different brush if the default is not desired return hbr; } Please mail me

        L Offline
        L Offline
        Laxman Auti
        wrote on last edited by
        #5

        See the following answer posted in the same page... Here[^] Knock out 't' from can't, You can if you think you can :cool:

        1 Reply Last reply
        0
        • _ _AnsHUMAN_

          HBRUSH CAfterone::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Change any attributes of the DC here if(pWnd->GetDlgCtrlID()==/*Put your control id Here ex IDC_EDIT1*/) // return your color brush here // TODO: Return a different brush if the default is not desired return hbr; } Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_

          Y Offline
          Y Offline
          yogendra kaushik
          wrote on last edited by
          #6

          i want only to change edit box color not text color this will change all dialog box coloto black i want to change only edit control color but not its text color plz tel me how this possible Please mail me

          _ L H 3 Replies Last reply
          0
          • Y yogendra kaushik

            i want only to change edit box color not text color this will change all dialog box coloto black i want to change only edit control color but not its text color plz tel me how this possible Please mail me

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

            Here's the code snippet : To change only the background color

            HBRUSH CTestDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
            {
            	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
            
            	// TODO:  Change any attributes of the DC here
            	HBRUSH hBr=CreateSolidBrush (RGB(255,0,0));
                   
                    if(pWnd->GetDlgCtrlID ()== IDC_EDIT1)
            	{
            	    pDC->SetBkColor (RGB(255,0,0));
            	    hbr=hBr;
            	}
            	// TODO:  Return a different brush if the default is not desired
            	return hbr;
            }
            

            Is it OK! Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_

            1 Reply Last reply
            0
            • Y yogendra kaushik

              i want only to change edit box color not text color this will change all dialog box coloto black i want to change only edit control color but not its text color plz tel me how this possible Please mail me

              L Offline
              L Offline
              Laxman Auti
              wrote on last edited by
              #8

              yogendra kaushik wrote:

              i want only to change edit box color not text color this will change all dialog box coloto black i want to change only edit control color but not its text color plz tel me how this possible

              The following code changes the color of the all the EDIT controls of the dialog CtestMFCDlg. HBRUSH CtestMFCDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if(nCtlColor== CTLCOLOR_EDIT ) hbr=CreateSolidBrush(RGB(0,100,0)); return hbr; } :) Knock out 't' from can't, You can if you think you can :cool:

              N 1 Reply Last reply
              0
              • Y yogendra kaushik

                i want only to change edit box color not text color this will change all dialog box coloto black i want to change only edit control color but not its text color plz tel me how this possible Please mail me

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

                you need to WM_CTLCOLOREDIT message_**


                **_

                whitesky


                1 Reply Last reply
                0
                • L Laxman Auti

                  yogendra kaushik wrote:

                  i want only to change edit box color not text color this will change all dialog box coloto black i want to change only edit control color but not its text color plz tel me how this possible

                  The following code changes the color of the all the EDIT controls of the dialog CtestMFCDlg. HBRUSH CtestMFCDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if(nCtlColor== CTLCOLOR_EDIT ) hbr=CreateSolidBrush(RGB(0,100,0)); return hbr; } :) Knock out 't' from can't, You can if you think you can :cool:

                  N Offline
                  N Offline
                  Naveen
                  wrote on last edited by
                  #10

                  A_Laxmanhbr=CreateSolidBrush(RGB(0,100,0));

                  this will generate handle leake...Isn't it? nave

                  1 Reply Last reply
                  0
                  • Y yogendra kaushik

                    hi all plz help me i want to change color of a particular control on which text is displayed but problem is that when i try folloeing code it will change color only of the text's background but not of all control plz tel me code for this HBRUSH CAfterone::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Change any attributes of the DC here pDC->SetBkColor(RGB(0, 0, 0)); // TODO: Return a different brush if the default is not desired return hbr; } Please mail me

                    M Offline
                    M Offline
                    Mahesh Kulkarni
                    wrote on last edited by
                    #11

                    yogendra kaushik wrote:

                    i want to change color of a particular control

                    I think following code will solve ur problem if(pWnd->GetDlgCtrlID()==IDC_EDIT1) { CRect rect; pWnd->GetClientRect(&rect); pDC->FillSolidRect(&rect,RGB(255,0,0)); pWnd->ReleaseDC(pDC); } put this code in OnCtlColor (). This wil give you desired output. The secret of life is not enjoyment but education through experience. - Swami Vivekananda.

                    Y 1 Reply Last reply
                    0
                    • M Mahesh Kulkarni

                      yogendra kaushik wrote:

                      i want to change color of a particular control

                      I think following code will solve ur problem if(pWnd->GetDlgCtrlID()==IDC_EDIT1) { CRect rect; pWnd->GetClientRect(&rect); pDC->FillSolidRect(&rect,RGB(255,0,0)); pWnd->ReleaseDC(pDC); } put this code in OnCtlColor (). This wil give you desired output. The secret of life is not enjoyment but education through experience. - Swami Vivekananda.

                      Y Offline
                      Y Offline
                      yogendra kaushik
                      wrote on last edited by
                      #12

                      thanks a lot mut if i want to change color of many edit boxes then i had to use if statement for each or there is some other techniqe to sole it plz send me code Please mail me

                      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