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. How to Update Dialog values

How to Update Dialog values

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestionannouncement
9 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.
  • S Offline
    S Offline
    simoncoul
    wrote on last edited by
    #1

    Hi I'm getting streaming data to the program I'm writing and I need to update the data constantly. I'm currently just doing a switch statement to determine what needs to be updated and then after the switch I have UpdateData(false); This works but it will not allow me to enter values into over boxes in the display as it is constantly being updated. Is there a way to update just the single box value and not the whole display? Thanks Simon

    D 1 Reply Last reply
    0
    • S simoncoul

      Hi I'm getting streaming data to the program I'm writing and I need to update the data constantly. I'm currently just doing a switch statement to determine what needs to be updated and then after the switch I have UpdateData(false); This works but it will not allow me to enter values into over boxes in the display as it is constantly being updated. Is there a way to update just the single box value and not the whole display? Thanks Simon

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

      simoncoul wrote:

      Is there a way to update just the single box value and not the whole display?

      Sure, just use ClassWizard (Ctrl+W) to assign a control variable to each control on the dialog. For edit, static, and button controls, use SetWindowText(). For listboxes and comboboxes, use AddString().


      "A good athlete is the result of a good and worthy opponent." - David Crow

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      S 1 Reply Last reply
      0
      • D David Crow

        simoncoul wrote:

        Is there a way to update just the single box value and not the whole display?

        Sure, just use ClassWizard (Ctrl+W) to assign a control variable to each control on the dialog. For edit, static, and button controls, use SetWindowText(). For listboxes and comboboxes, use AddString().


        "A good athlete is the result of a good and worthy opponent." - David Crow

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        S Offline
        S Offline
        simoncoul
        wrote on last edited by
        #3

        Hey thanks for the quick reply, but the SetWindowText asks for a LPCTSTR as the argument but I need to do integers and sometimes floats. Can I just cast it? Thanks again

        M D J 3 Replies Last reply
        0
        • S simoncoul

          Hey thanks for the quick reply, but the SetWindowText asks for a LPCTSTR as the argument but I need to do integers and sometimes floats. Can I just cast it? Thanks again

          M Offline
          M Offline
          Manfred Staiger
          wrote on last edited by
          #4

          There are functions for appropriate conversion, for example itoa, ltoa. Or, if you are using CString: long var =12345; CString strVar; strVar.Format( "%d", var );

          MS

          1 Reply Last reply
          0
          • S simoncoul

            Hey thanks for the quick reply, but the SetWindowText asks for a LPCTSTR as the argument but I need to do integers and sometimes floats. Can I just cast it? Thanks again

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

            simoncoul wrote:

            Can I just cast it?

            No. Use:

            char szData[16];
            int nValue = 12345;
            sprintf(szData, "%d", nValue);
            ...
            double dValue = 987.01;
            sprintf(szData, "%f", dValue);

            By chance are you using MFC?


            "A good athlete is the result of a good and worthy opponent." - David Crow

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            S 1 Reply Last reply
            0
            • D David Crow

              simoncoul wrote:

              Can I just cast it?

              No. Use:

              char szData[16];
              int nValue = 12345;
              sprintf(szData, "%d", nValue);
              ...
              double dValue = 987.01;
              sprintf(szData, "%f", dValue);

              By chance are you using MFC?


              "A good athlete is the result of a good and worthy opponent." - David Crow

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              S Offline
              S Offline
              simoncoul
              wrote on last edited by
              #6

              Yes I am, does that make this easier?

              D 1 Reply Last reply
              0
              • S simoncoul

                Yes I am, does that make this easier?

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

                simoncoul wrote:

                does that make this easier?

                Not necessarily easier, but slightly more elegant and efficient:

                CString strData;
                int nValue = 12345;
                strData.Format("%d", nValue);
                ...
                double dValue = 987.01;
                strData.Format("%f", dValue);


                "A good athlete is the result of a good and worthy opponent." - David Crow

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                S 1 Reply Last reply
                0
                • D David Crow

                  simoncoul wrote:

                  does that make this easier?

                  Not necessarily easier, but slightly more elegant and efficient:

                  CString strData;
                  int nValue = 12345;
                  strData.Format("%d", nValue);
                  ...
                  double dValue = 987.01;
                  strData.Format("%f", dValue);


                  "A good athlete is the result of a good and worthy opponent." - David Crow

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  S Offline
                  S Offline
                  simoncoul
                  wrote on last edited by
                  #8

                  Thanks for all the help guys!

                  1 Reply Last reply
                  0
                  • S simoncoul

                    Hey thanks for the quick reply, but the SetWindowText asks for a LPCTSTR as the argument but I need to do integers and sometimes floats. Can I just cast it? Thanks again

                    J Offline
                    J Offline
                    jhwurmbach
                    wrote on last edited by
                    #9

                    simoncoul wrote:

                    Can I just cast it?

                    No. There is a routine you cann add to yotu program called boost::lexical_cast[^] which allows you to use a simple cast. (The documentation even describes what is going on under the hood) double pi = 3.14; std::string number = boost::lexical_cast( pi);


                    Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                    George Orwell, "Keep the Aspidistra Flying", Opening words

                    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