How can I get and set the 'read-only' property of an edit box?
views:
1040answers:
3
A:
From the design window: right-click the edit box, select properties. Its the last option on the Styles tab.
yhw
2009-01-20 20:59:33
Thanks, but I meant during runtime.
2009-01-20 21:16:05
+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
2009-01-20 21:10:10
Hmm.. I am getting this 'SetReadOnly' : is not a member of 'CWnd'Anything special about this?
2009-01-20 21:29:20
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
2009-01-20 21:45:39
Yes, that's what I'm doing. Is that not the standard way of doing it? What's another way? TIA
2009-01-20 21:47:26
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
2009-01-20 22:11:09
Actually casting CWnd* to CEdit* is idiomatic MFC. Just one of the many reasons it gets no respect.
Mark Ransom
2009-02-21 23:33:56
A:
GetDlgItem(blah)->SendMessage(EM_SETREADONLY ,1 ,0);
This will set it to read only.
kobkob
2009-10-25 12:49:27