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. set the color to a Button

set the color to a Button

Scheduled Pinned Locked Moved C / C++ / MFC
question
9 Posts 7 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.
  • C Offline
    C Offline
    chetan210183
    wrote on last edited by
    #1

    Hi, Is it possible to set the color to a button in a dialog based application? I tried using CTLCOLOR_BTN unsuccessfully. The code which i tried is given below.. HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (CTLCOLOR_BTN == nCtlColor) // It worked when i used CTLCOLOR_DLG to change the color of the DialogBox { hbr = ::GetSysColorBrush(1); } return hbr; } Thanks in Adavance.. Chetan. Helping others satisfies you...

    H N T S I 7 Replies Last reply
    0
    • C chetan210183

      Hi, Is it possible to set the color to a button in a dialog based application? I tried using CTLCOLOR_BTN unsuccessfully. The code which i tried is given below.. HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (CTLCOLOR_BTN == nCtlColor) // It worked when i used CTLCOLOR_DLG to change the color of the DialogBox { hbr = ::GetSysColorBrush(1); } return hbr; } Thanks in Adavance.. Chetan. Helping others satisfies you...

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

      I think you want to change color from button you need to derived from CButton and use WM_DRAWITEM But for best way you can go examples in CodeProject and you find your answer

      C 1 Reply Last reply
      0
      • C chetan210183

        Hi, Is it possible to set the color to a button in a dialog based application? I tried using CTLCOLOR_BTN unsuccessfully. The code which i tried is given below.. HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (CTLCOLOR_BTN == nCtlColor) // It worked when i used CTLCOLOR_DLG to change the color of the DialogBox { hbr = ::GetSysColorBrush(1); } return hbr; } Thanks in Adavance.. Chetan. Helping others satisfies you...

        N Offline
        N Offline
        Nishad S
        wrote on last edited by
        #3

        You will get a good knowledge about button costumization from http://www.codeproject.com/useritems/HyperButtonEx.asp - NS -

        1 Reply Last reply
        0
        • C chetan210183

          Hi, Is it possible to set the color to a button in a dialog based application? I tried using CTLCOLOR_BTN unsuccessfully. The code which i tried is given below.. HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (CTLCOLOR_BTN == nCtlColor) // It worked when i used CTLCOLOR_DLG to change the color of the DialogBox { hbr = ::GetSysColorBrush(1); } return hbr; } Thanks in Adavance.. Chetan. Helping others satisfies you...

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          The art of Subclassing[^]

          1 Reply Last reply
          0
          • C chetan210183

            Hi, Is it possible to set the color to a button in a dialog based application? I tried using CTLCOLOR_BTN unsuccessfully. The code which i tried is given below.. HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (CTLCOLOR_BTN == nCtlColor) // It worked when i used CTLCOLOR_DLG to change the color of the DialogBox { hbr = ::GetSysColorBrush(1); } return hbr; } Thanks in Adavance.. Chetan. Helping others satisfies you...

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #5

            The documentation states that WM_CTLCOLORBTN (which you're handling indirectly via the MFC plumbing when you handle the WM_CTLCOLOR message) only works you owner drawn controls - Which basically makes it useless as then you have to draw it yourself. You’re not doing anything wrong; this technique simply doesn’t work. Steve

            1 Reply Last reply
            0
            • C chetan210183

              Hi, Is it possible to set the color to a button in a dialog based application? I tried using CTLCOLOR_BTN unsuccessfully. The code which i tried is given below.. HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (CTLCOLOR_BTN == nCtlColor) // It worked when i used CTLCOLOR_DLG to change the color of the DialogBox { hbr = ::GetSysColorBrush(1); } return hbr; } Thanks in Adavance.. Chetan. Helping others satisfies you...

              I Offline
              I Offline
              includeh10
              wrote on last edited by
              #6

              simplest way is to Inherit a CButton then darw it on WM_PAINT or OnPaint(...), very easy.


              A nice tool for optimizing your Microsoft html-help contents. Includeh10

              1 Reply Last reply
              0
              • C chetan210183

                Hi, Is it possible to set the color to a button in a dialog based application? I tried using CTLCOLOR_BTN unsuccessfully. The code which i tried is given below.. HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (CTLCOLOR_BTN == nCtlColor) // It worked when i used CTLCOLOR_DLG to change the color of the DialogBox { hbr = ::GetSysColorBrush(1); } return hbr; } Thanks in Adavance.. Chetan. Helping others satisfies you...

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

                chetan210183 wrote:

                I tried using CTLCOLOR_BTN unsuccessfully.

                Button Doesn't support Changing color through WM_CTLCOLOR Message!.. you need to handle WM_DRAWITEM MESSAGE by Subclassing the Button... look for exmple for same here http://www.codeproject.com/button

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

                cheers, Alok Gupta VC Forum Q&A :- I/ IV

                1 Reply Last reply
                0
                • H Hamid Taebi

                  I think you want to change color from button you need to derived from CButton and use WM_DRAWITEM But for best way you can go examples in CodeProject and you find your answer

                  C Offline
                  C Offline
                  chetan210183
                  wrote on last edited by
                  #8

                  Thanks a lot for your suggestion. Helping others satisfies you...

                  1 Reply Last reply
                  0
                  • C chetan210183

                    Hi, Is it possible to set the color to a button in a dialog based application? I tried using CTLCOLOR_BTN unsuccessfully. The code which i tried is given below.. HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (CTLCOLOR_BTN == nCtlColor) // It worked when i used CTLCOLOR_DLG to change the color of the DialogBox { hbr = ::GetSysColorBrush(1); } return hbr; } Thanks in Adavance.. Chetan. Helping others satisfies you...

                    C Offline
                    C Offline
                    chetan210183
                    wrote on last edited by
                    #9

                    Thanks a lot. Helping others satisfies you...

                    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