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. a question of edit control

a question of edit control

Scheduled Pinned Locked Moved C / C++ / MFC
question
11 Posts 5 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    when I click in my editbox,I want all the contents to be selected,I used these code: void CCaculatorDlg::OnSetfocusEDITap1() { CEdit* ped=(CEdit*)GetDlgItem(IDC_EDIT_ap1); ped->SetSel(0, -1, FALSE); } but it doesnt work, when I click at the editbox, it just like havent added these code. what could I do?

    L V J 3 Replies Last reply
    0
    • L Lost User

      when I click in my editbox,I want all the contents to be selected,I used these code: void CCaculatorDlg::OnSetfocusEDITap1() { CEdit* ped=(CEdit*)GetDlgItem(IDC_EDIT_ap1); ped->SetSel(0, -1, FALSE); } but it doesnt work, when I click at the editbox, it just like havent added these code. what could I do?

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

      Did you try handling GetFocus instead of SetFocus?

      I 1 Reply Last reply
      0
      • L Lost User

        when I click in my editbox,I want all the contents to be selected,I used these code: void CCaculatorDlg::OnSetfocusEDITap1() { CEdit* ped=(CEdit*)GetDlgItem(IDC_EDIT_ap1); ped->SetSel(0, -1, FALSE); } but it doesnt work, when I click at the editbox, it just like havent added these code. what could I do?

        V Offline
        V Offline
        valikac
        wrote on last edited by
        #3

        Use EN_SETSEL ----- // editHWnd is the handle to your edit control // from and to are the beginning and end of your select range SendMessage(editHWnd, EM_SETSEL, static_cast(from), static_cast(to)); ----- Kuphryn

        T 1 Reply Last reply
        0
        • T Tomasz Sowinski

          There's no EN_SETSEL. Tomasz Sowinski -- http://www.shooltz.com

          - It's for protection
          - Protection from what? Zee Germans?

          V Offline
          V Offline
          valikac
          wrote on last edited by
          #4

          I meant EM_SETSEL. Kuphryn

          T 1 Reply Last reply
          0
          • V valikac

            Use EN_SETSEL ----- // editHWnd is the handle to your edit control // from and to are the beginning and end of your select range SendMessage(editHWnd, EM_SETSEL, static_cast(from), static_cast(to)); ----- Kuphryn

            T Offline
            T Offline
            Tomasz Sowinski
            wrote on last edited by
            #5

            There's no EN_SETSEL. Tomasz Sowinski -- http://www.shooltz.com

            - It's for protection
            - Protection from what? Zee Germans?

            V 1 Reply Last reply
            0
            • T Tomasz Sowinski

              And what do you think CEdit::SetSel does? Tomasz Sowinski -- http://www.shooltz.com

              - It's for protection
              - Protection from what? Zee Germans?

              V Offline
              V Offline
              valikac
              wrote on last edited by
              #6

              There are more than one way to get it working. Using EM_SETSEL is another method. I recommend trying that method to see if get the design where you want it. Kuphryn

              T 1 Reply Last reply
              0
              • V valikac

                I meant EM_SETSEL. Kuphryn

                T Offline
                T Offline
                Tomasz Sowinski
                wrote on last edited by
                #7

                And what do you think CEdit::SetSel does? Tomasz Sowinski -- http://www.shooltz.com

                - It's for protection
                - Protection from what? Zee Germans?

                V 1 Reply Last reply
                0
                • V valikac

                  There are more than one way to get it working. Using EM_SETSEL is another method. I recommend trying that method to see if get the design where you want it. Kuphryn

                  T Offline
                  T Offline
                  Tomasz Sowinski
                  wrote on last edited by
                  #8

                  Just FYI, CEdit::SetSel is a thin wrapper which sends EM_SETSEL. So there's no difference, unless you want to achieve macho-API posture. :) Tomasz Sowinski -- http://www.shooltz.com

                  - It's for protection
                  - Protection from what? Zee Germans?

                  1 Reply Last reply
                  0
                  • L Lost User

                    when I click in my editbox,I want all the contents to be selected,I used these code: void CCaculatorDlg::OnSetfocusEDITap1() { CEdit* ped=(CEdit*)GetDlgItem(IDC_EDIT_ap1); ped->SetSel(0, -1, FALSE); } but it doesnt work, when I click at the editbox, it just like havent added these code. what could I do?

                    J Offline
                    J Offline
                    James R Twine
                    wrote on last edited by
                    #9

                    Two things: First (as I go into Pedantic mode...) Anonymous wrote: CEdit* ped=(CEdit*)GetDlgItem(IDC_EDIT_ap1); ped->SetSel(0, -1, FALSE);    I would recommend that you do not get into the habit of casting the return value of GetDlgItem(...) to a CEdit* (or other class type) like that.  There are certain situations where GetDlgItem(...) will return a pointer to a real CEdit (or other Control Class) object, but if you do not know what those situations are, it is best to avoid this entirely.  Bind a CEdit member variable to the control, and use it instead.    True, in the case of MFC, doing that is usually safe, but in general C++ practices, it is a bad thing to do: you do not know if the pointer returned by GetDlgItem(...) is, or ever was, a pointer to an actual CEdit object.    Second, try using PostMessage(...) to send yourself the EM_SETSEL message from inside the OnSetFocus handler.    BTW: CWnd::OnSetFocus(...) is a standard function.  What is OnSetfocusEDITap1 supposed to be?  You may be handling the WM_SETFOCUS message incorrectly.    Peace! -=- James. "Some People Know How To Drive, Others Just Know How To Operate A Car." (Try Check Favorites Sometime!)

                    I 1 Reply Last reply
                    0
                    • L Lost User

                      Did you try handling GetFocus instead of SetFocus?

                      I Offline
                      I Offline
                      ilavl
                      wrote on last edited by
                      #10

                      but there's no message like GetFocus, (I look it up in class wizard)

                      1 Reply Last reply
                      0
                      • J James R Twine

                        Two things: First (as I go into Pedantic mode...) Anonymous wrote: CEdit* ped=(CEdit*)GetDlgItem(IDC_EDIT_ap1); ped->SetSel(0, -1, FALSE);    I would recommend that you do not get into the habit of casting the return value of GetDlgItem(...) to a CEdit* (or other class type) like that.  There are certain situations where GetDlgItem(...) will return a pointer to a real CEdit (or other Control Class) object, but if you do not know what those situations are, it is best to avoid this entirely.  Bind a CEdit member variable to the control, and use it instead.    True, in the case of MFC, doing that is usually safe, but in general C++ practices, it is a bad thing to do: you do not know if the pointer returned by GetDlgItem(...) is, or ever was, a pointer to an actual CEdit object.    Second, try using PostMessage(...) to send yourself the EM_SETSEL message from inside the OnSetFocus handler.    BTW: CWnd::OnSetFocus(...) is a standard function.  What is OnSetfocusEDITap1 supposed to be?  You may be handling the WM_SETFOCUS message incorrectly.    Peace! -=- James. "Some People Know How To Drive, Others Just Know How To Operate A Car." (Try Check Favorites Sometime!)

                        I Offline
                        I Offline
                        ilavl
                        wrote on last edited by
                        #11

                        yeah, I thought there must be sth wrong with the function OnSetfocusEDITap1,I thought may be there is a function named OnGetFocus...., but I failed to find it. Have you met this question?

                        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