Pelles C forum

C language => Windows questions => Topic started by: tpekar on August 16, 2012, 07:12:59 PM

Title: Changing a edit box to static or read only
Post by: tpekar on August 16, 2012, 07:12:59 PM
I was wondering if anyone can show me how to change an edit box control to static, or if not, at least make it read only?  I would also need to change it back.
Title: Re: Changing a edit box to static or read only
Post by: Stefan Pendl on August 16, 2012, 10:38:21 PM
You would use the EM_SETREADONLY message (http://msdn.microsoft.com/en-us/library/windows/desktop/bb761655%28v=vs.85%29.aspx) to change the edit control to read only and back.

You could also disable it if the user shouldn't even be allowed to copy the contents of the edit control.
Title: Re: Changing a edit box to static or read only
Post by: tpekar on August 16, 2012, 10:59:25 PM
That worked.  Thanks!!  Question.  How come EM_SETREADONLY and not ES_READONLY?
Title: Re: Changing a edit box to static or read only
Post by: Stefan Pendl on August 17, 2012, 07:35:07 AM
EM = Edit Message ... you use the message to change the behavior of the control after it is created

ES = Edit Style ... you can only apply the style when you create the control

To change the style without the message, you would need the GetWindowLong and SetWindowLong functions, see the remarks of the page linked above.

Always make sure to read the whole page, especially the remarks and requirements.