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. About OnCtlColor

About OnCtlColor

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

    I want a button to diplay the red text sometime, so I create a class derived from CButton and override the OnCtlColor handler, as below: HBRUSH CColorButton::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CButton::OnCtlColor(pDC, pWnd, nCtlColor); if(m_iFlag == 1) pDC->SetTextColor(0x000000ff); return hbr; } but I found the handler didn't be executed even when the dialog initialized, How can I do the work I want. Thanx.

    J R R 3 Replies Last reply
    0
    • O olinn

      I want a button to diplay the red text sometime, so I create a class derived from CButton and override the OnCtlColor handler, as below: HBRUSH CColorButton::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CButton::OnCtlColor(pDC, pWnd, nCtlColor); if(m_iFlag == 1) pDC->SetTextColor(0x000000ff); return hbr; } but I found the handler didn't be executed even when the dialog initialized, How can I do the work I want. Thanx.

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      This does not answer your question, but it may solve your problem: check Yury Goltsman's article Colored/Blinking Controls and Dialogs with any Font [^]. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      O 1 Reply Last reply
      0
      • J Joaquin M Lopez Munoz

        This does not answer your question, but it may solve your problem: check Yury Goltsman's article Colored/Blinking Controls and Dialogs with any Font [^]. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        O Offline
        O Offline
        olinn
        wrote on last edited by
        #3

        Thank you. I saw the source code and found the way he accomplished the work seamed the same as mine. I just wonder why my overrided message handler OnCtlColor didn't be executed, as I set a break point in the handler, no stoping occured when I debuged.

        1 Reply Last reply
        0
        • O olinn

          I want a button to diplay the red text sometime, so I create a class derived from CButton and override the OnCtlColor handler, as below: HBRUSH CColorButton::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CButton::OnCtlColor(pDC, pWnd, nCtlColor); if(m_iFlag == 1) pDC->SetTextColor(0x000000ff); return hbr; } but I found the handler didn't be executed even when the dialog initialized, How can I do the work I want. Thanx.

          R Offline
          R Offline
          Ryan Binns
          wrote on last edited by
          #4

          Are you using ON_WM_CTLCOLOR() or ON_WM_CTLCOLOR_REFLECT() in your message map? Since your OnCtlColor() function is in your button, you need to use ON_WM_CTLCOLOR_REFLECT(). If you're not, just replace the message map entry and it will work fine. Hope this helps, Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
          Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"

          O 1 Reply Last reply
          0
          • R Ryan Binns

            Are you using ON_WM_CTLCOLOR() or ON_WM_CTLCOLOR_REFLECT() in your message map? Since your OnCtlColor() function is in your button, you need to use ON_WM_CTLCOLOR_REFLECT(). If you're not, just replace the message map entry and it will work fine. Hope this helps, Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
            Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"

            O Offline
            O Offline
            olinn
            wrote on last edited by
            #5

            Yeth, I also found that is the point just now. It seems that the ON_WM_CTLCOLOR message could only be managed by parent wnd, I replaced it with ON_WM_CTLCOLOR_REFLECT and overrided CtlColor() (not OnCtlColor) and it worked. Thank you. Does it means only I need is to manage the ON_WM_CTLCOLOR_REFLECT message but ON_WM_CTLCOLOR?

            R 1 Reply Last reply
            0
            • O olinn

              Yeth, I also found that is the point just now. It seems that the ON_WM_CTLCOLOR message could only be managed by parent wnd, I replaced it with ON_WM_CTLCOLOR_REFLECT and overrided CtlColor() (not OnCtlColor) and it worked. Thank you. Does it means only I need is to manage the ON_WM_CTLCOLOR_REFLECT message but ON_WM_CTLCOLOR?

              R Offline
              R Offline
              Ryan Binns
              wrote on last edited by
              #6

              You don't need ON_WM_CTLCOLOR(), only ON_WM_CTLCOLOR_REFLECT() Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
              Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"

              1 Reply Last reply
              0
              • O olinn

                I want a button to diplay the red text sometime, so I create a class derived from CButton and override the OnCtlColor handler, as below: HBRUSH CColorButton::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CButton::OnCtlColor(pDC, pWnd, nCtlColor); if(m_iFlag == 1) pDC->SetTextColor(0x000000ff); return hbr; } but I found the handler didn't be executed even when the dialog initialized, How can I do the work I want. Thanx.

                R Offline
                R Offline
                RChin
                wrote on last edited by
                #7

                Olinn
                Have a look at the msdn article Visual C++/MFC Frequently Asked Questions__, in the MSDN library. I haven't got the web link, but the extract is shown below:

                How do I change the background color of a button? Note: the method in "How do I change the background color of a control?" will not work for buttons! If you want to change the color of a dialog button, you have to use an owner-draw button. (You can use bitmap buttons.) Changing the color through OnCtlColor() will not work for buttons. The following Knowledge Base articles may be of help to you: Q32685, "Using the WM_CTLCOLOR Message," and Q64328, "SAMPLE: Owner-Draw: 3-D Push Button Made from Bitmaps with Text." This article explains sample code for a owner-draw button. Ramesh (NetQuest), MSMFC, 8/3/95



                "..Even my comments have bugs!"
                Inspired by Toni78__

                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