July 4th, 2007, 03:44 AM
[C++] How do I disable edit features in an edit control?
Q: How do I disable edit features in an edit control?
A: If you want to disable all the edit features of an edit control and still want to access its features like adding / appending a string and display the text in wrapped lines, here is a simple method to do this.
But, before that, about the other easy methods to achieve similar things: One can as well create read only edit control. But the look is different for read only edit controls with background painted as gray. Moreover, one can focus the edit control in the tab order or by clicking on it and the cursor will be shown in the edit control when it is in focus. You can as well disable the edit control since disabled edit controls suppress the cursor and prevents user from selecting it through tab order or by mouse click. But, information displayed cannot be easily read due to the dimmed way text is written. Changing colour of text or appearances of the control is difficult without sub-classing the edit control.
Here is an easier method to make an edit control look as a panel of static information, but still can be treated programmatically as a normal edit control.
The method I used here is to handle the EN_SETFOCUS message in the parent window, of which edit control is a part. In the message handler, I simply set the focus to the parent window itself.
If you are inserting the control using resource editor, you can right-click the control and handle the event of notification message EN_SETFOCUS. If you are programmatically inserting the control, you will have to define the function in the header file
will have to make the message map entries in your class implementation
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSetfocusMessage();
and finally have to shift the focus from the edit control in the message handler
This works fine as far as prevention of selecting with mouse is concerned. But, when the control is defined in a particular tab order, focus will be simply lost when one presses TAB from the previous control, since focus is on the parent window. Next TAB press will bring the focus to the first control in the tab order. Hence, there will be an abnormality of behaviour. One of the easiest way to solve this is to declare this edit control as the last item in tab order. If there are multiple panels of information like this, they all can be pushed to the last in the tab order.
// TODO: Add your control notification handler code here
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.