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. Problem displaying CStatic text item

Problem displaying CStatic text item

Scheduled Pinned Locked Moved C / C++ / MFC
helplearning
23 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
    ForNow
    wrote on last edited by
    #1

    Hi. I am all sorts of issues displaying a text on my dialog so first let me say what's involved I have a CStatic ptr says CStatic *mytext I instintate this say mytext = new CStatic; The next few steps im not sure of the order So now I want to connect this CWnd object to my resource file Id in my DIALOGEX resource says its a CTEXT so I call UpdateData or CDialog::OnInitDialog which does that for me The DDX_control connects my CTEXT to mytext CWnd object next I do a mytext->SetWindowText however nothing appears within my CDialog Do first have to do SetWindowText before DDX_control if DDX_control initilizes the CTEXT with what text is in my text then maybe I do I have tried all sorts of methods including DrawText to display the text whitin the dialog but I get nothing displayed

    J D 2 Replies Last reply
    0
    • F ForNow

      Hi. I am all sorts of issues displaying a text on my dialog so first let me say what's involved I have a CStatic ptr says CStatic *mytext I instintate this say mytext = new CStatic; The next few steps im not sure of the order So now I want to connect this CWnd object to my resource file Id in my DIALOGEX resource says its a CTEXT so I call UpdateData or CDialog::OnInitDialog which does that for me The DDX_control connects my CTEXT to mytext CWnd object next I do a mytext->SetWindowText however nothing appears within my CDialog Do first have to do SetWindowText before DDX_control if DDX_control initilizes the CTEXT with what text is in my text then maybe I do I have tried all sorts of methods including DrawText to display the text whitin the dialog but I get nothing displayed

      J Online
      J Online
      jeron1
      wrote on last edited by
      #2

      Can't you just add the CStatic control to the dialog via the resource editor? Then associate a CString variable to it and use UpdateData()? In your code how did you size the CStatic control? Did you use the Create() method anywhere to give it its size, style, initial text, etc?

      "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

      F 1 Reply Last reply
      0
      • J jeron1

        Can't you just add the CStatic control to the dialog via the resource editor? Then associate a CString variable to it and use UpdateData()? In your code how did you size the CStatic control? Did you use the Create() method anywhere to give it its size, style, initial text, etc?

        "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

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

        Hi I use MoveWindow to size it I think calling CDialog::OnInitDialog will call UpdateData to connect the resource in my case CTEXT to the CWnd object After wards in my ::OnInitDialog I use MoveWindow followed by SetWindowText for the control and ShowWindow for both the control and dialog box I then do a return TRUE However nothing is displayed

        J 1 Reply Last reply
        0
        • F ForNow

          Hi I use MoveWindow to size it I think calling CDialog::OnInitDialog will call UpdateData to connect the resource in my case CTEXT to the CWnd object After wards in my ::OnInitDialog I use MoveWindow followed by SetWindowText for the control and ShowWindow for both the control and dialog box I then do a return TRUE However nothing is displayed

          J Online
          J Online
          jeron1
          wrote on last edited by
          #4

          Call the create Create() method with initial values and see if anything displays.

          "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

          F 1 Reply Last reply
          0
          • J jeron1

            Call the create Create() method with initial values and see if anything displays.

            "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

            F Offline
            F Offline
            ForNow
            wrote on last edited by
            #5

            With the text as the first parm. Ok I'm at work will try tommorow thanks for your help

            J 1 Reply Last reply
            0
            • F ForNow

              With the text as the first parm. Ok I'm at work will try tommorow thanks for your help

              J Online
              J Online
              jeron1
              wrote on last edited by
              #6

              I have to ask, are there reasons why you can't use the resource editor to add the CStatic control, as opposed to using ptr = new CStatic?

              "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

              F 1 Reply Last reply
              0
              • J jeron1

                I have to ask, are there reasons why you can't use the resource editor to add the CStatic control, as opposed to using ptr = new CStatic?

                "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

                F Offline
                F Offline
                ForNow
                wrote on last edited by
                #7

                I am connecting via Tcp/ip CAsyncSockets to another computer the information I receive will be displaed in the CStatic

                J 1 Reply Last reply
                0
                • F ForNow

                  I am connecting via Tcp/ip CAsyncSockets to another computer the information I receive will be displaed in the CStatic

                  J Online
                  J Online
                  jeron1
                  wrote on last edited by
                  #8

                  But the dialog and display controls in it don't care where the data comes from. Typically (at least for me), when I build a dialog using the resource editor, I place a static control on the dialog, just like I place edit boxes, list boxes, etc. I then create a variable associated with that static control (typically using a wizard), the variable could be a CString type or a control type. If I use a CString type variable, I use UpdateData(), if I use a control type variable I use SetWindowText() and that's about it. Seems like you might be making it unecessarily more complicated.

                  "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

                  F 1 Reply Last reply
                  0
                  • J jeron1

                    But the dialog and display controls in it don't care where the data comes from. Typically (at least for me), when I build a dialog using the resource editor, I place a static control on the dialog, just like I place edit boxes, list boxes, etc. I then create a variable associated with that static control (typically using a wizard), the variable could be a CString type or a control type. If I use a CString type variable, I use UpdateData(), if I use a control type variable I use SetWindowText() and that's about it. Seems like you might be making it unecessarily more complicated.

                    "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

                    F Offline
                    F Offline
                    ForNow
                    wrote on last edited by
                    #9

                    Thanks so much i am displaying z/OS (mainframe data on windows) I am mainframe programmer and its people like yourself that have helped me understand MFC So can I call Updatedata to initialize the CTEXT I am assuming no that I am not using a control but rather a variable it would be DDX_Text I might also add that I have Richeditctrl in the dialog I am displaying a storage area in the richedit And the static info are things like what storage area it came from like subpool Storage protection key I also noticed DDX_Text takes unit I would assume it converts it to CString before the display Thanks again

                    F 1 Reply Last reply
                    0
                    • F ForNow

                      Thanks so much i am displaying z/OS (mainframe data on windows) I am mainframe programmer and its people like yourself that have helped me understand MFC So can I call Updatedata to initialize the CTEXT I am assuming no that I am not using a control but rather a variable it would be DDX_Text I might also add that I have Richeditctrl in the dialog I am displaying a storage area in the richedit And the static info are things like what storage area it came from like subpool Storage protection key I also noticed DDX_Text takes unit I would assume it converts it to CString before the display Thanks again

                      F Offline
                      F Offline
                      ForNow
                      wrote on last edited by
                      #10

                      Sorry But my question is can I call UpdateData from anywhere or does it have to be from CDialog::Oninitdialig

                      L 1 Reply Last reply
                      0
                      • F ForNow

                        Hi. I am all sorts of issues displaying a text on my dialog so first let me say what's involved I have a CStatic ptr says CStatic *mytext I instintate this say mytext = new CStatic; The next few steps im not sure of the order So now I want to connect this CWnd object to my resource file Id in my DIALOGEX resource says its a CTEXT so I call UpdateData or CDialog::OnInitDialog which does that for me The DDX_control connects my CTEXT to mytext CWnd object next I do a mytext->SetWindowText however nothing appears within my CDialog Do first have to do SetWindowText before DDX_control if DDX_control initilizes the CTEXT with what text is in my text then maybe I do I have tried all sorts of methods including DrawText to display the text whitin the dialog but I get nothing displayed

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

                        ForNow wrote:

                        I have a CStatic ptr says CStatic *mytext

                        Why use a pointer? Just add:

                        CStatic mytext;

                        to your dialog's header file. Add an entry to your dialog's DoDataExchange() method like:

                        DDX_Control(pDX, IDC_MYTEXT, mytext);

                        Then in your dialog's OnInitDialog() method, set the control's text like:

                        mytext.SetWindowText(_T("Hello World"));

                        And that's it! No need for pointers, memory allocation, or messy calls to UpdateData().

                        "One man's wage rise is another man's price increase." - Harold Wilson

                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                        F 1 Reply Last reply
                        0
                        • D David Crow

                          ForNow wrote:

                          I have a CStatic ptr says CStatic *mytext

                          Why use a pointer? Just add:

                          CStatic mytext;

                          to your dialog's header file. Add an entry to your dialog's DoDataExchange() method like:

                          DDX_Control(pDX, IDC_MYTEXT, mytext);

                          Then in your dialog's OnInitDialog() method, set the control's text like:

                          mytext.SetWindowText(_T("Hello World"));

                          And that's it! No need for pointers, memory allocation, or messy calls to UpdateData().

                          "One man's wage rise is another man's price increase." - Harold Wilson

                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                          F Offline
                          F Offline
                          ForNow
                          wrote on last edited by
                          #12

                          Thanks in a related question if I wanted to change the font of the text I'm guessing I would do that in a the OnCtlColor would I use pWnd->SetFont (of course after I created a font) with CreateFontIndirect or would I use the pDC and do pDC->SelectObject Thanks

                          D 1 Reply Last reply
                          0
                          • F ForNow

                            Sorry But my question is can I call UpdateData from anywhere or does it have to be from CDialog::Oninitdialig

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #13

                            You can call it from anywhere. You usually call it first from CDialog::OnInitDialog to set the initial values of the variables. Then you call it at other times, in response to user input to save any new values.

                            1 Reply Last reply
                            0
                            • F ForNow

                              Thanks in a related question if I wanted to change the font of the text I'm guessing I would do that in a the OnCtlColor would I use pWnd->SetFont (of course after I created a font) with CreateFontIndirect or would I use the pDC and do pDC->SelectObject Thanks

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

                              See the "Bold static controls" section of this article.

                              "One man's wage rise is another man's price increase." - Harold Wilson

                              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                              F 1 Reply Last reply
                              0
                              • D David Crow

                                See the "Bold static controls" section of this article.

                                "One man's wage rise is another man's price increase." - Harold Wilson

                                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                                F Offline
                                F Offline
                                ForNow
                                wrote on last edited by
                                #15

                                You are really helpful I am going to press my luck and ask the following if the variable was a CString using DDX_Text as per jeron1 would I then look to change The font in OnCtlColor Thanks Thanks

                                D J 2 Replies Last reply
                                0
                                • F ForNow

                                  You are really helpful I am going to press my luck and ask the following if the variable was a CString using DDX_Text as per jeron1 would I then look to change The font in OnCtlColor Thanks Thanks

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

                                  I do not know. In 23 years of using MFC, I've never used a CString as an interface to a static control. Give it a whirl and let us know how it works.

                                  "One man's wage rise is another man's price increase." - Harold Wilson

                                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                                  "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                                  1 Reply Last reply
                                  0
                                  • F ForNow

                                    You are really helpful I am going to press my luck and ask the following if the variable was a CString using DDX_Text as per jeron1 would I then look to change The font in OnCtlColor Thanks Thanks

                                    J Online
                                    J Online
                                    jeron1
                                    wrote on last edited by
                                    #17

                                    I can't imagine setting or changing the font color being affected by the type of variable (CString or CStatic)associated with the control.

                                    "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

                                    F 1 Reply Last reply
                                    0
                                    • J jeron1

                                      I can't imagine setting or changing the font color being affected by the type of variable (CString or CStatic)associated with the control.

                                      "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

                                      F Offline
                                      F Offline
                                      ForNow
                                      wrote on last edited by
                                      #18

                                      I was just looking to change the font of a control associated with a CString David's suggestion would work if I associated the control with a CStatic CWnd object Thanks

                                      J 1 Reply Last reply
                                      0
                                      • F ForNow

                                        I was just looking to change the font of a control associated with a CString David's suggestion would work if I associated the control with a CStatic CWnd object Thanks

                                        J Online
                                        J Online
                                        jeron1
                                        wrote on last edited by
                                        #19

                                        Another way could be like something shown here[^].

                                        "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

                                        F 1 Reply Last reply
                                        0
                                        • J jeron1

                                          Another way could be like something shown here[^].

                                          "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

                                          F Offline
                                          F Offline
                                          ForNow
                                          wrote on last edited by
                                          #20

                                          http://www.flounder.com/viewfont.htm[^] Would I need to implement WM_SETFONT WM_GETFONT as per this article

                                          J 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