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. Reg - Edit Box

Reg - Edit Box

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialhelp
11 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.
  • P Paulraj G

    Hi... Hi i am having a multiline text box. Initially i have some data in edit box. Then if i add any data, the previous datas are gone. i want both previous and current data. For example, I am Having "This is Test \r\n This is multiline text box". if i add "This is second line", the editbox should show both data. How to do... Please help me. I used,

    CString str1 = "Some String";
    GetDlgItemText(IDC_EDIT1, str);
    str2 = str+str1;
    SetDlgItemText(IDC_EDIT1, str2);

    Please tell me is there any otherway....

    G.Paulraj

    K Offline
    K Offline
    KingsGambit
    wrote on last edited by
    #2

    You can try EM_REPLACESEL message. CString cs; GetDlgItemText(IDC_EDIT1, cs); SendDlgItemMessage(IDC_EDIT1, EM_SETSEL, cs.GetLength(), cs.GetLength()); SendDlgItemMessage(IDC_EDIT1, EM_REPLACESEL, 0, (LPARAM)_T("Some String"));

    modified on Wednesday, December 23, 2009 5:34 AM

    R 1 Reply Last reply
    0
    • P Paulraj G

      Hi... Hi i am having a multiline text box. Initially i have some data in edit box. Then if i add any data, the previous datas are gone. i want both previous and current data. For example, I am Having "This is Test \r\n This is multiline text box". if i add "This is second line", the editbox should show both data. How to do... Please help me. I used,

      CString str1 = "Some String";
      GetDlgItemText(IDC_EDIT1, str);
      str2 = str+str1;
      SetDlgItemText(IDC_EDIT1, str2);

      Please tell me is there any otherway....

      G.Paulraj

      R Offline
      R Offline
      Rajesh R Subramanian
      wrote on last edited by
      #3

      Use a control type member variable for the edit control. Then do something like

      m_Edit.GetWindowText(szTemp );
      szTemp += _T("Whatever");
      m_Edit.SetWindowText(szTemp);

      “Follow your bliss.” – Joseph Campbell

      1 Reply Last reply
      0
      • K KingsGambit

        You can try EM_REPLACESEL message. CString cs; GetDlgItemText(IDC_EDIT1, cs); SendDlgItemMessage(IDC_EDIT1, EM_SETSEL, cs.GetLength(), cs.GetLength()); SendDlgItemMessage(IDC_EDIT1, EM_REPLACESEL, 0, (LPARAM)_T("Some String"));

        modified on Wednesday, December 23, 2009 5:34 AM

        R Offline
        R Offline
        Rajesh R Subramanian
        wrote on last edited by
        #4

        Good suggestion. :)

        “Follow your bliss.” – Joseph Campbell

        K 1 Reply Last reply
        0
        • R Rajesh R Subramanian

          Good suggestion. :)

          “Follow your bliss.” – Joseph Campbell

          K Offline
          K Offline
          KingsGambit
          wrote on last edited by
          #5

          Thank you! :)

          R 1 Reply Last reply
          0
          • K KingsGambit

            Thank you! :)

            R Offline
            R Offline
            Rajesh R Subramanian
            wrote on last edited by
            #6

            OK you modified that post. While I thought the EM_REPLACESEL itself was a great idea, I wouldn't have liked the usage of GetDlgItem() call. But hey, different people, different ways. (why I don't like GetDlgItem()? Because I'm a terrific fan of Dr. Joseph Newcomer, and his philosophies and I take 'em seriously). Added: Look at my second answer to the OP. :)

            “Follow your bliss.” – Joseph Campbell

            modified on Wednesday, December 23, 2009 5:48 AM

            K 1 Reply Last reply
            0
            • P Paulraj G

              Hi... Hi i am having a multiline text box. Initially i have some data in edit box. Then if i add any data, the previous datas are gone. i want both previous and current data. For example, I am Having "This is Test \r\n This is multiline text box". if i add "This is second line", the editbox should show both data. How to do... Please help me. I used,

              CString str1 = "Some String";
              GetDlgItemText(IDC_EDIT1, str);
              str2 = str+str1;
              SetDlgItemText(IDC_EDIT1, str2);

              Please tell me is there any otherway....

              G.Paulraj

              R Offline
              R Offline
              Rajesh R Subramanian
              wrote on last edited by
              #7

              Hi, You might want to try this (thanks to Rejeesh for his EM_REPLACESEL suggestion, which triggered this idea)

              int len = m_Edit.GetWindowTextLength(); //find the length of text in the control
              m_Edit.SetSel(len, len, 0); //select nothing (but the cursor goes to the end)
              m_Edit.ReplaceSel(szNewText); //new text will be printed at the end now!

              “Follow your bliss.” – Joseph Campbell

              K 1 Reply Last reply
              0
              • R Rajesh R Subramanian

                OK you modified that post. While I thought the EM_REPLACESEL itself was a great idea, I wouldn't have liked the usage of GetDlgItem() call. But hey, different people, different ways. (why I don't like GetDlgItem()? Because I'm a terrific fan of Dr. Joseph Newcomer, and his philosophies and I take 'em seriously). Added: Look at my second answer to the OP. :)

                “Follow your bliss.” – Joseph Campbell

                modified on Wednesday, December 23, 2009 5:48 AM

                K Offline
                K Offline
                KingsGambit
                wrote on last edited by
                #8

                Me too don't like to use GetDlgItem(). It is always better and clean to use binded members with DDX/DDV. I thought I would provide an answer which resembles the sample code segment in the post :). Thanks for the comment.

                L 1 Reply Last reply
                0
                • R Rajesh R Subramanian

                  Hi, You might want to try this (thanks to Rejeesh for his EM_REPLACESEL suggestion, which triggered this idea)

                  int len = m_Edit.GetWindowTextLength(); //find the length of text in the control
                  m_Edit.SetSel(len, len, 0); //select nothing (but the cursor goes to the end)
                  m_Edit.ReplaceSel(szNewText); //new text will be printed at the end now!

                  “Follow your bliss.” – Joseph Campbell

                  K Offline
                  K Offline
                  KingsGambit
                  wrote on last edited by
                  #9

                  This is the MFC way. Now the code looks cleaner :)

                  P 1 Reply Last reply
                  0
                  • K KingsGambit

                    This is the MFC way. Now the code looks cleaner :)

                    P Offline
                    P Offline
                    Paulraj G
                    wrote on last edited by
                    #10

                    Sorry for deleyed reply... Thanks for Both of you... the problem has been solved...

                    G.Paulraj

                    1 Reply Last reply
                    0
                    • K KingsGambit

                      Me too don't like to use GetDlgItem(). It is always better and clean to use binded members with DDX/DDV. I thought I would provide an answer which resembles the sample code segment in the post :). Thanks for the comment.

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

                      Rejeesh.T.S wrote:

                      Me too don't like to use GetDlgItem(). It is always better and clean to use binded members with DDX/DDV.

                      You do realize, of course, that DDX_ macros internally call GetDlgItem? Newcomer's screed on the subject overlooks that fact. It really comes down to personal preference in coding style; one way is no more evil than another. Personally I try to avoid MFC-specific API's where possible - it makes porting code between frameworks a little less painful.

                      L u n a t i c F r i n g e

                      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