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. CStatic-Derived class: painting background

CStatic-Derived class: painting background

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestion
10 Posts 5 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.
  • 4 Offline
    4 Offline
    4288
    wrote on last edited by
    #1

    Hi all, I need to paint the background of a CStatic control created dynamically this way:

    CUnknownCtrl* pUnknown;
    pUnknown = new CUnknownCtrl;
    pUnknown->Create("Text", SS_CENTER | WS_CHILD | WS_VISIBLE | WS_GROUP, CRect(11,35,360,526), this, 0x31);

    Notice that CUnknownCtrl is a CStatic-derived mfc class. I can't figure out how to set background color of the label created with this code, someone can help me? Calling OnCtlColor inside CUnknownCtrl won't even be executed and OnPaint fails. Some idea? Thanks for advance

    ---

    N L H 3 Replies Last reply
    0
    • 4 4288

      Hi all, I need to paint the background of a CStatic control created dynamically this way:

      CUnknownCtrl* pUnknown;
      pUnknown = new CUnknownCtrl;
      pUnknown->Create("Text", SS_CENTER | WS_CHILD | WS_VISIBLE | WS_GROUP, CRect(11,35,360,526), this, 0x31);

      Notice that CUnknownCtrl is a CStatic-derived mfc class. I can't figure out how to set background color of the label created with this code, someone can help me? Calling OnCtlColor inside CUnknownCtrl won't even be executed and OnPaint fails. Some idea? Thanks for advance

      ---

      N Offline
      N Offline
      Nitheesh George
      wrote on last edited by
      #2

      Hi, Simply handle the WM_CTLCOLORSTATIC message in your class. The WM_CTLCOLORSTATIC is send to a static control when its background color need to drawn. thanks. Nitheesh

      G 1 Reply Last reply
      0
      • 4 4288

        Hi all, I need to paint the background of a CStatic control created dynamically this way:

        CUnknownCtrl* pUnknown;
        pUnknown = new CUnknownCtrl;
        pUnknown->Create("Text", SS_CENTER | WS_CHILD | WS_VISIBLE | WS_GROUP, CRect(11,35,360,526), this, 0x31);

        Notice that CUnknownCtrl is a CStatic-derived mfc class. I can't figure out how to set background color of the label created with this code, someone can help me? Calling OnCtlColor inside CUnknownCtrl won't even be executed and OnPaint fails. Some idea? Thanks for advance

        ---

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #3

        4288 wrote:

        and OnPaint fails

        What does that mean?

        led mike

        4 1 Reply Last reply
        0
        • L led mike

          4288 wrote:

          and OnPaint fails

          What does that mean?

          led mike

          4 Offline
          4 Offline
          4288
          wrote on last edited by
          #4

          I used OnCtlColor handler, but because my label was created with a CStatic-derived class, the code provided into CMyClass::OnCtlColor won't be executed! OnPaint seemed me a good solution but if I insert the OnPaint handler with Visual Studio, the control won't even show

          ---

          L 1 Reply Last reply
          0
          • 4 4288

            I used OnCtlColor handler, but because my label was created with a CStatic-derived class, the code provided into CMyClass::OnCtlColor won't be executed! OnPaint seemed me a good solution but if I insert the OnPaint handler with Visual Studio, the control won't even show

            ---

            L Offline
            L Offline
            led mike
            wrote on last edited by
            #5

            4288 wrote:

            but if I insert the OnPaint handler with Visual Studio, the control won't even show

            Did you subclass the control?[^]

            led mike

            4 1 Reply Last reply
            0
            • L led mike

              4288 wrote:

              but if I insert the OnPaint handler with Visual Studio, the control won't even show

              Did you subclass the control?[^]

              led mike

              4 Offline
              4 Offline
              4288
              wrote on last edited by
              #6

              I thought I subclassed it, but my subclassing seems not to work. Have you got please a link that show how to perform a subclassing with a dynamical control created like mine?

              ---

              1 Reply Last reply
              0
              • N Nitheesh George

                Hi, Simply handle the WM_CTLCOLORSTATIC message in your class. The WM_CTLCOLORSTATIC is send to a static control when its background color need to drawn. thanks. Nitheesh

                G Offline
                G Offline
                Gary R Wheeler
                wrote on last edited by
                #7

                WM_CTLCOLORSTATIC is sent to the parent window of the static control, not the static control itself.

                Software Zen: delete this;
                Fold With Us![^]

                1 Reply Last reply
                0
                • 4 4288

                  Hi all, I need to paint the background of a CStatic control created dynamically this way:

                  CUnknownCtrl* pUnknown;
                  pUnknown = new CUnknownCtrl;
                  pUnknown->Create("Text", SS_CENTER | WS_CHILD | WS_VISIBLE | WS_GROUP, CRect(11,35,360,526), this, 0x31);

                  Notice that CUnknownCtrl is a CStatic-derived mfc class. I can't figure out how to set background color of the label created with this code, someone can help me? Calling OnCtlColor inside CUnknownCtrl won't even be executed and OnPaint fails. Some idea? Thanks for advance

                  ---

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

                  See here[^].

                  4 1 Reply Last reply
                  0
                  • H Hamid Taebi

                    See here[^].

                    4 Offline
                    4 Offline
                    4288
                    wrote on last edited by
                    #9

                    Problem solved, thanks!

                    ---

                    H 1 Reply Last reply
                    0
                    • 4 4288

                      Problem solved, thanks!

                      ---

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

                      Very good. :-D

                      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