CEdit的Clear方法

做Win32或MFC开发,有不清楚的问题一定记得先查MSDN!

做Win32或MFC开发,有不清楚的问题一定记得先查MSDN!

做Win32或MFC开发,有不清楚的问题一定记得先查MSDN!

CEdit控件有个Clear方法,之前我一直以为是清除文本的,有点像SetWindowText(_T("")),但有一次这样使用后发现并不是自己想象的那样,随后照旧用SetWindowText,但这个疑问就那样扔下了。

最近查资料,偶然翻到MSDN,看到关于CEdit的Clear方法说明,如下:

Call this function to delete (clear) the current selection (if any) in the edit control.

Remarks

The deletion performed by Clear can be undone by calling the Undo member function.

To delete the current selection and place the deleted contents into the Clipboard, call the Cut member function.

For more information, see WM_CLEAR in the Platform SDK.

原来它是在不影响剪切板的情况下,清除当前选中的文本。假如你既要删除,又要将删除文本放入剪切板,就调用Cut方法。

因此,Clear方法并不是清除控件文本,那么清除控件文本还有没有其他方法,MSDN提供了一个例子:

// The pointer to my edit.
extern CEdit* pmyEdit;

// Delete all of the text.
pmyEdit->SetSel(0, -1);
pmyEdit->Clear();

清除控件文本,除了SetWindowText(_T("")),还可以用上述方式。

看到这里,问题终于有了答案。

作者:快雪
本文版权归作者所有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/kuaixue/p/14962939.html