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. static text

static text

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
5 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.
  • F Offline
    F Offline
    FarPointer
    wrote on last edited by
    #1

    how to change colour of static text at runtime.

    A D 2 Replies Last reply
    0
    • F FarPointer

      how to change colour of static text at runtime.

      A Offline
      A Offline
      Ashok Dhamija
      wrote on last edited by
      #2

      Try using SetTextColor function of CDC by trapping the ON_WM_CTLCOLOR() message. In the message-handler OnCtlColor, use code like this:

      HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
      {
      HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

      //Here m\_stText represents a CStatic control 
      if(m\_stText.m\_hWnd == pWnd->m\_hWnd)
      {
      	pDC->SetTextColor(RGB(0,0,155));
      }
      
      return hbr;
      

      }

      Regards, Ashok Dhamija _____________________________ Padam Technologies

      F 1 Reply Last reply
      0
      • A Ashok Dhamija

        Try using SetTextColor function of CDC by trapping the ON_WM_CTLCOLOR() message. In the message-handler OnCtlColor, use code like this:

        HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
        {
        HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

        //Here m\_stText represents a CStatic control 
        if(m\_stText.m\_hWnd == pWnd->m\_hWnd)
        {
        	pDC->SetTextColor(RGB(0,0,155));
        }
        
        return hbr;
        

        }

        Regards, Ashok Dhamija _____________________________ Padam Technologies

        F Offline
        F Offline
        FarPointer
        wrote on last edited by
        #3

        hi, thanks man it worked ,and for clearing the concept with that informative code I added the following code to get the CWnd* handle to the static control from the IDC_ CWnd *m_stText=GetDlgItem(IDC_STATIC);and i guess it doesnt work with the button. thanks Farpointer

        T 1 Reply Last reply
        0
        • F FarPointer

          how to change colour of static text at runtime.

          D Offline
          D Offline
          douglasjordan
          wrote on last edited by
          #4

          The WM_CTLCOLORSTATIC message is sent to the parent during drawing of the control. The HDC and HWND are provided to change the foreground colors. The return value is a brush to set the background.

          1 Reply Last reply
          0
          • F FarPointer

            hi, thanks man it worked ,and for clearing the concept with that informative code I added the following code to get the CWnd* handle to the static control from the IDC_ CWnd *m_stText=GetDlgItem(IDC_STATIC);and i guess it doesnt work with the button. thanks Farpointer

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

            farpointer wrote: guess it doesnt work with the button. thanks For Coloring the Button you either have to subclass it or make it owner drawn...

            "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
            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