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 lock an edit box?

How to lock an edit box?

Scheduled Pinned Locked Moved C / C++ / MFC
c++jsontutorialquestion
7 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.
  • A Offline
    A Offline
    Aidman
    wrote on last edited by
    #1

    Hi, all I was wondering how to lock (not disable) an edit box during runtime, so the content (the text) in the control can still be selected but not modified/edited. I am using regular Windows API (no MFC) and I also want to be able to unlock the edit box. Thanks in advance :) Aidman » over and out We haven't inherited Earth from our parents, instead we have borrowed her from our children; an old Indian saying.

    B P E 3 Replies Last reply
    0
    • A Aidman

      Hi, all I was wondering how to lock (not disable) an edit box during runtime, so the content (the text) in the control can still be selected but not modified/edited. I am using regular Windows API (no MFC) and I also want to be able to unlock the edit box. Thanks in advance :) Aidman » over and out We haven't inherited Earth from our parents, instead we have borrowed her from our children; an old Indian saying.

      B Offline
      B Offline
      Beer26
      wrote on last edited by
      #2

      if you want to do this easily, you'll probably want to use CRichEditCtrl with the read only property enabled instead of CEdit

      P 1 Reply Last reply
      0
      • A Aidman

        Hi, all I was wondering how to lock (not disable) an edit box during runtime, so the content (the text) in the control can still be selected but not modified/edited. I am using regular Windows API (no MFC) and I also want to be able to unlock the edit box. Thanks in advance :) Aidman » over and out We haven't inherited Earth from our parents, instead we have borrowed her from our children; an old Indian saying.

        P Offline
        P Offline
        peterchen
        wrote on last edited by
        #3

        Either use the ES_READONLY style when you create it, or the EM_SETREADONLY message (CEdit::SetReadOnly if you use MFC) at any time after creatign the control


        "Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
        sighist | Agile Programming | doxygen

        1 Reply Last reply
        0
        • B Beer26

          if you want to do this easily, you'll probably want to use CRichEditCtrl with the read only property enabled instead of CEdit

          P Offline
          P Offline
          peterchen
          wrote on last edited by
          #4

          You can do that to an Edit, too...


          "Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
          sighist | Agile Programming | doxygen

          B 1 Reply Last reply
          0
          • P peterchen

            You can do that to an Edit, too...


            "Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
            sighist | Agile Programming | doxygen

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

            doesn't setting read only on an Edit gray the box by default? If so, and I can remember it doing that, you'd have to subclass and override. That's why I suggested the rich edit instead.

            P 1 Reply Last reply
            0
            • B Beer26

              doesn't setting read only on an Edit gray the box by default? If so, and I can remember it doing that, you'd have to subclass and override. That's why I suggested the rich edit instead.

              P Offline
              P Offline
              peterchen
              wrote on last edited by
              #6

              yes it does - (I thought that would be ok with the asker) However, there's a message you can override in the dialog to proivde a different background brush. Peter


              "Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
              sighist | Agile Programming | doxygen

              1 Reply Last reply
              0
              • A Aidman

                Hi, all I was wondering how to lock (not disable) an edit box during runtime, so the content (the text) in the control can still be selected but not modified/edited. I am using regular Windows API (no MFC) and I also want to be able to unlock the edit box. Thanks in advance :) Aidman » over and out We haven't inherited Earth from our parents, instead we have borrowed her from our children; an old Indian saying.

                E Offline
                E Offline
                Erik Funkenbusch
                wrote on last edited by
                #7

                As others have mentioned, you use the EM_SETREADONLY message. However, this will cause the edit box to be grayed out. You can still select the text, copy it, etc.. If you want the control to look like a normal edit control, but be read-only, then you need to catch WM_CONTROLCOLOR and look for the controls window handle and return a brush that's the same as the users color preferences. I'd advise against that, though. It confuses users when a control looks editable, but really isn't. -- Where are we going? And why am I in this handbasket?

                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