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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Changing caption of static control at run time

Changing caption of static control at run time

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
5 Posts 4 Posters 2 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.
  • B Offline
    B Offline
    BiswaR
    wrote on last edited by
    #1

    Can any one please explain me how to change the the caption of a static control at run time based on some condition.For example during the OnInitDialog function of the dialog on which the control is there.

    I R A 3 Replies Last reply
    0
    • B BiswaR

      Can any one please explain me how to change the the caption of a static control at run time based on some condition.For example during the OnInitDialog function of the dialog on which the control is there.

      I Offline
      I Offline
      Iain Clarke Warrior Programmer
      wrote on last edited by
      #2

      BOOL CMyDialog::OnInitDialog ()
      {
      SetDlgItemText (IDC_A_STATIC_TEXT, "New Text. Whoopidoo");

      return CDialog::OnInitDialog ();
      

      }

      You have to give the static control an ID in the dialog editor, and ID_STATIC does not uniquely identify the control. Iain.

      B 1 Reply Last reply
      0
      • B BiswaR

        Can any one please explain me how to change the the caption of a static control at run time based on some condition.For example during the OnInitDialog function of the dialog on which the control is there.

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

        Use the SetWindowText function. So if you have a static control with id IDC_STATIC1. Then you would change the text using: GetDlgItem(IDC_STATIC1)->SetWindowText(_T("Ta Da!"));


        I Dream of Absolute Zero

        1 Reply Last reply
        0
        • B BiswaR

          Can any one please explain me how to change the the caption of a static control at run time based on some condition.For example during the OnInitDialog function of the dialog on which the control is there.

          A Offline
          A Offline
          Andre xxxxxxx
          wrote on last edited by
          #4

          Change IDC_STATIC to a unique name (IDC_MYSTATIC) and then go into the class wizard -> member variables -> select your static control -> Add member. In the "Add member" dialog select CString and enter a name for your member variable, m_sMyStatic for example. Now you can change the caption of the static control with m_sMyStatic = "My new caption"; UpdateData (FALSE); André

          1 Reply Last reply
          0
          • I Iain Clarke Warrior Programmer

            BOOL CMyDialog::OnInitDialog ()
            {
            SetDlgItemText (IDC_A_STATIC_TEXT, "New Text. Whoopidoo");

            return CDialog::OnInitDialog ();
            

            }

            You have to give the static control an ID in the dialog editor, and ID_STATIC does not uniquely identify the control. Iain.

            B Offline
            B Offline
            BiswaR
            wrote on last edited by
            #5

            Hey Guys, Thanks a lot for you help. Exactly the same i was trying yesterday but that was not working i do not know why. I think ihad some problems.Thanks a lot again.

            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