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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. color of button control

color of button control

Scheduled Pinned Locked Moved C / C++ / MFC
help
12 Posts 4 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.
  • A Offline
    A Offline
    ashish dogra
    wrote on last edited by
    #1

    hi please help me tell me how i can change the color of a button control and text on it which are differ from dialog box. A button is on a dialog box Ashish Dogra MCA Noida

    A H 3 Replies Last reply
    0
    • A ashish dogra

      hi please help me tell me how i can change the color of a button control and text on it which are differ from dialog box. A button is on a dialog box Ashish Dogra MCA Noida

      A Offline
      A Offline
      anothervip
      wrote on last edited by
      #2

      I think you can change the button color in CWnd::OnCtlColor (WM_CTLCOLOR) of the parent window and change the text color by SetTextColor().

      A 1 Reply Last reply
      0
      • A ashish dogra

        hi please help me tell me how i can change the color of a button control and text on it which are differ from dialog box. A button is on a dialog box Ashish Dogra MCA Noida

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

        You can use a class derived CButton and use WM_DRAWITEM of course you need to set OwnerDraw in property button in property window_**


        **_

        whitesky


        1 Reply Last reply
        0
        • A anothervip

          I think you can change the button color in CWnd::OnCtlColor (WM_CTLCOLOR) of the parent window and change the text color by SetTextColor().

          A Offline
          A Offline
          ashish dogra
          wrote on last edited by
          #4

          thanks form reply but sir i use this one but it does not change the color HBRUSH CButtoncolorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if(nCtlColor == CTLCOLOR_BTN) { hbr=CreateSolidBrush(RGB(0,100,0)); pDC->SetTextColor(RGB(0,0,255)); pDC->SetBkColor(RGB(0,100,0)); } return hbr; } Ashish Dogra MCA Noida

          _ A 2 Replies Last reply
          0
          • A ashish dogra

            thanks form reply but sir i use this one but it does not change the color HBRUSH CButtoncolorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if(nCtlColor == CTLCOLOR_BTN) { hbr=CreateSolidBrush(RGB(0,100,0)); pDC->SetTextColor(RGB(0,0,255)); pDC->SetBkColor(RGB(0,100,0)); } return hbr; } Ashish Dogra MCA Noida

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

            Did you set the BS_OWNERDRAW property of the button's to TRUE. I guess not.Do it and then you will see the button color change. To change the property of the button to owner draw right click on the button . Open the property window and just set the OWNER Draw property to true. IS it OK? Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_

            A 2 Replies Last reply
            0
            • A ashish dogra

              thanks form reply but sir i use this one but it does not change the color HBRUSH CButtoncolorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if(nCtlColor == CTLCOLOR_BTN) { hbr=CreateSolidBrush(RGB(0,100,0)); pDC->SetTextColor(RGB(0,0,255)); pDC->SetBkColor(RGB(0,100,0)); } return hbr; } Ashish Dogra MCA Noida

              A Offline
              A Offline
              anothervip
              wrote on last edited by
              #6

              HBRUSH CButtoncolorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if(nCtlColor == CTLCOLOR_BTN) { if( pWnd == "Your specific button pointer" ) return CreateSolidBrush(RGB(0,100,0)); } return hbr; } I wonder maybe you need to use new font ( by SelectObject() ) to change the font color.

              1 Reply Last reply
              0
              • _ _AnsHUMAN_

                Did you set the BS_OWNERDRAW property of the button's to TRUE. I guess not.Do it and then you will see the button color change. To change the property of the button to owner draw right click on the button . Open the property window and just set the OWNER Draw property to true. IS it OK? Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_

                A Offline
                A Offline
                ashish dogra
                wrote on last edited by
                #7

                THANKS Ashish Dogra MCA Noida

                1 Reply Last reply
                0
                • _ _AnsHUMAN_

                  Did you set the BS_OWNERDRAW property of the button's to TRUE. I guess not.Do it and then you will see the button color change. To change the property of the button to owner draw right click on the button . Open the property window and just set the OWNER Draw property to true. IS it OK? Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_

                  A Offline
                  A Offline
                  ashish dogra
                  wrote on last edited by
                  #8

                  hi again i am sorry to disturb you again but i make an application in which many dialog boxes are there now when i make ownerdraw property true the application does not run and if i make ownerdraw property false the application runs i dont understand the problem so plz tell me what is the problem thanks Ashish Dogra MCA Noida

                  H 1 Reply Last reply
                  0
                  • A ashish dogra

                    hi please help me tell me how i can change the color of a button control and text on it which are differ from dialog box. A button is on a dialog box Ashish Dogra MCA Noida

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

                    I think you need to one code so see this you need to insert this code in your project for one start

                    m_Button.ModifyStyle(0,BS_OWNERDRAW); //in your main class insert this code
                    m_Button is CMyButton1
                    //////////////////
                    
                    ///////////in header file
                    class CMyButton1 : public CButton
                    {
                    	DECLARE_DYNAMIC(CMyButton1)
                    
                    public:
                    	CMyButton1();
                    	virtual ~CMyButton1();
                    protected:
                    	DECLARE_MESSAGE_MAP()
                    public:
                    	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
                    };
                    
                    
                    IMPLEMENT_DYNAMIC(CMyButton1, CButton)
                    CMyButton1::CMyButton1()
                    {
                    }
                    
                    CMyButton1::~CMyButton1()
                    {
                    }
                    
                    
                    BEGIN_MESSAGE_MAP(CMyButton1, CButton)
                    	
                    END_MESSAGE_MAP()
                    
                    void CMyButton1::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
                    {
                    CDC dc;
                    dc.Attach(lpDrawItemStruct->hDC);
                    CRect rt;
                    rt = lpDrawItemStruct->rcItem;
                    
                    
                    dc.SetBkMode(0);
                    
                    CString str;
                    GetWindowText(str);
                    
                    if ( (lpDrawItemStruct->itemState & ODS_SELECTED) )
                    {
                    dc.FrameRect(&rt,&CBrush(RGB(110,170,210)));
                    dc.SetTextColor(RGB(0,0,0));
                    dc.FillRect(&rt,&CBrush(RGB(190,210,210)));
                    }
                    else
                    {
                    dc.FrameRect(&rt,&CBrush(RGB(0,0,0)));
                    dc.SetTextColor(RGB(255,255,255));
                    dc.FillRect(&rt,&CBrush(RGB(100,170,210)));
                    }
                    dc.DrawText(str,rt,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
                    dc.Detach();
                    }
                    

                    _**


                    **_

                    whitesky


                    1 Reply Last reply
                    0
                    • A ashish dogra

                      hi again i am sorry to disturb you again but i make an application in which many dialog boxes are there now when i make ownerdraw property true the application does not run and if i make ownerdraw property false the application runs i dont understand the problem so plz tell me what is the problem thanks Ashish Dogra MCA Noida

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

                      whats error you get one error when you set Ownerdraw,right?_**


                      **_

                      whitesky


                      A 1 Reply Last reply
                      0
                      • H Hamid Taebi

                        whats error you get one error when you set Ownerdraw,right?_**


                        **_

                        whitesky


                        A Offline
                        A Offline
                        ashish dogra
                        wrote on last edited by
                        #11

                        application does not run it simply show an message that application has encountreda problem and need to close Ashish Dogra MCA Noida

                        H 1 Reply Last reply
                        0
                        • A ashish dogra

                          application does not run it simply show an message that application has encountreda problem and need to close Ashish Dogra MCA Noida

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

                          see my example i hope you find why when you use ownerdraw you get error. in MSDN you see: "BS_OWNERDRAW Creates an owner-drawn button. The owner window receives a WM_DRAWITEM message when a visual aspect of the button has changed. Do not combine the BS_OWNERDRAW style with any other button styles."_**


                          **_

                          whitesky


                          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