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. color the text in MFC Dialog

color the text in MFC Dialog

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

    Hi, everyone: Can someone provide a EZ way to change an individual text in a dialog? I knew that I can use CDC functions to realize that, but can I do this on a Static Control? To talk in detail, I wanna use SetWindowText() or SetDlgItemText( ) to change the text of a control containing some text string. And what should I do to change the reulting text? Or don't think about that, simply use CDC functions? Thanks!

    V D 2 Replies Last reply
    0
    • Y ytod

      Hi, everyone: Can someone provide a EZ way to change an individual text in a dialog? I knew that I can use CDC functions to realize that, but can I do this on a Static Control? To talk in detail, I wanna use SetWindowText() or SetDlgItemText( ) to change the text of a control containing some text string. And what should I do to change the reulting text? Or don't think about that, simply use CDC functions? Thanks!

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      Handle the WM_CTLCOLOR message. In VS call the properties for the dialog, there you can set handlers for messages, in that list is a WM_CTLCOLOR message. Choose a function to handle this. Write something like this in it: HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); CBrush *brush; brush = NULL; // TODO: Change any attributes of the DC here CWnd* pStaticWnd = (CWnd*)GetDlgItem(IDC_STATIC_STATUS); if(pWnd == pStaticWnd){ pDC->SetTextColor(RGB(0, 0, 255)); } //end if pStaticWnd = (CWnd*)GetDlgItem(IDC_STATIC_INFO_DOC); if(pWnd == pStaticWnd){ if(lock_docstatus_text){ pDC->SetTextColor(RGB(0, 100, 200)); } //end if else{ pDC->SetTextColor(RGB(0, 0, 255)); } //end else } //end if pStaticWnd = (CWnd*)GetDlgItem(IDC_STATIC_INFO_SEND); if(pWnd == pStaticWnd){ if(lock_sendstatus_text){ pDC->SetTextColor(RGB(0, 100, 200)); } //end if else{ pDC->SetTextColor(RGB(0, 0, 255)); } //end else } //end if // TODO: Return a different brush if the default is not desired return hbr; for more info check out msdn. Hope this helps, good luck. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

      Y 1 Reply Last reply
      0
      • Y ytod

        Hi, everyone: Can someone provide a EZ way to change an individual text in a dialog? I knew that I can use CDC functions to realize that, but can I do this on a Static Control? To talk in detail, I wanna use SetWindowText() or SetDlgItemText( ) to change the text of a control containing some text string. And what should I do to change the reulting text? Or don't think about that, simply use CDC functions? Thanks!

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        ytod wrote: To talk in detail, I wanna use SetWindowText() or SetDlgItemText( ) to change the text of a control containing some text string. And what should I do to change the reulting text? You just answered your own question. Use SetWindowText().


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

        Y 1 Reply Last reply
        0
        • D David Crow

          ytod wrote: To talk in detail, I wanna use SetWindowText() or SetDlgItemText( ) to change the text of a control containing some text string. And what should I do to change the reulting text? You just answered your own question. Use SetWindowText().


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

          Y Offline
          Y Offline
          ytod
          wrote on last edited by
          #4

          DavidCrow wrote: ytod wrote: To talk in detail, I wanna use SetWindowText() or SetDlgItemText( ) to change the text of a control containing some text string. And what should I do to change the reulting text? ;P Miss one word "color": And what should I do to change the reulting text "color"? But I need to try what the previous post described first, thanks!

          D 1 Reply Last reply
          0
          • V V 0

            Handle the WM_CTLCOLOR message. In VS call the properties for the dialog, there you can set handlers for messages, in that list is a WM_CTLCOLOR message. Choose a function to handle this. Write something like this in it: HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); CBrush *brush; brush = NULL; // TODO: Change any attributes of the DC here CWnd* pStaticWnd = (CWnd*)GetDlgItem(IDC_STATIC_STATUS); if(pWnd == pStaticWnd){ pDC->SetTextColor(RGB(0, 0, 255)); } //end if pStaticWnd = (CWnd*)GetDlgItem(IDC_STATIC_INFO_DOC); if(pWnd == pStaticWnd){ if(lock_docstatus_text){ pDC->SetTextColor(RGB(0, 100, 200)); } //end if else{ pDC->SetTextColor(RGB(0, 0, 255)); } //end else } //end if pStaticWnd = (CWnd*)GetDlgItem(IDC_STATIC_INFO_SEND); if(pWnd == pStaticWnd){ if(lock_sendstatus_text){ pDC->SetTextColor(RGB(0, 100, 200)); } //end if else{ pDC->SetTextColor(RGB(0, 0, 255)); } //end else } //end if // TODO: Return a different brush if the default is not desired return hbr; for more info check out msdn. Hope this helps, good luck. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

            Y Offline
            Y Offline
            ytod
            wrote on last edited by
            #5

            It didn't work.... But if the condition in if() changed to this form could work: if( pWnd->GetDlgCtrlID() == IDC_STATIC_MY_STATIC ) { pDC->SetTextColor(RGB(255, 0, 0)); } Anyway, thnks for your help.

            1 Reply Last reply
            0
            • Y ytod

              DavidCrow wrote: ytod wrote: To talk in detail, I wanna use SetWindowText() or SetDlgItemText( ) to change the text of a control containing some text string. And what should I do to change the reulting text? ;P Miss one word "color": And what should I do to change the reulting text "color"? But I need to try what the previous post described first, thanks!

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Using OnCtlColor(), or handling the WM_CTLCOLOR message, is the preferred method.


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

              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