views:

1040

answers:

3

How can I get and set the 'read-only' property of an edit box?

A: 

From the design window: right-click the edit box, select properties. Its the last option on the Styles tab.

yhw
Thanks, but I meant during runtime.
+4  A: 

The CEdit class has a SetReadOnly method which can be called at run-time. Details on MSDN: http://msdn.microsoft.com/en-gb/library/aa279328(VS.60).aspx

Steve Beedie
Hmm.. I am getting this 'SetReadOnly' : is not a member of 'CWnd'Anything special about this?
How are you calling it? If you're doing something like GetDlgItem(blah)->SetReadOnly, then you'll probably get an error message like that, because GetDlgItem doesn't return a CEdit.
Joel
Yes, that's what I'm doing. Is that not the standard way of doing it? What's another way? TIA
Probably the best way is to use the ClassWizard to set up a member variable for the control or controls you want to change and manipulate the edit control through that. You could probably cast the CWnd* to a CEdit*, but I wouldn't unless you're just out of other options.
Joel
Actually casting CWnd* to CEdit* is idiomatic MFC. Just one of the many reasons it gets no respect.
Mark Ransom
A: 
GetDlgItem(blah)->SendMessage(EM_SETREADONLY ,1 ,0);

This will set it to read only.

kobkob