yeah ----------------------------- CEdit::SetSel void SetSel( DWORD dwSelection, BOOL bNoScroll = FALSE );void SetSel( int nStartChar, int nEndChar, BOOL bNoScroll = FALSE );ParametersdwSelectionSpecifies the starting position in the low-order word and the ending position in the high-order word. If the low-order word is 0 and the high-order word is –1, all the text in the edit control is selected. If the low-order word is –1, any current selection is removed.bNoScrollIndicates whether the caret should be scrolled into view. If FALSE, the caret is scrolled into view. If TRUE, the caret is not scrolled into view.nStartCharSpecifies the starting position. If nStartChar is 0 and nEndChar is –1, all the text in the edit control is selected. If nStartChar is –1, any current selection is removed.nEndCharSpecifies the ending position.ResCall this function to select a range of characters in an edit control.
在里面调用setsel
-----------------------------
CEdit::SetSel
void SetSel( DWORD dwSelection, BOOL bNoScroll = FALSE );void SetSel( int nStartChar, int nEndChar, BOOL bNoScroll = FALSE );ParametersdwSelectionSpecifies the starting position in the low-order word and the ending position in the high-order word. If the low-order word is 0 and the high-order word is –1, all the text in the edit control is selected. If the low-order word is –1, any current selection is removed.bNoScrollIndicates whether the caret should be scrolled into view. If FALSE, the caret is scrolled into view. If TRUE, the caret is not scrolled into view.nStartCharSpecifies the starting position. If nStartChar is 0 and nEndChar is –1, all the text in the edit control is selected. If nStartChar is –1, any current selection is removed.nEndCharSpecifies the ending position.ResCall this function to select a range of characters in an edit control.
CNewEdit
然后重载OnSetFocus函数
在这个函数里使用SetSel(0,-1,TRUE);
如:CNewEdit
基类为CEdit
然后在你需要用到编辑框的对话框里调用头文件
打开ClassWizard替每个Edit加一个control变量,类型为CNewEdit
再打开CNewEdit的ClassWizard
为其加上一个OnSetFocus()函数
在这个函数里
SetSel(0,-1,TRUE);
一切OK
void CEditDlg::OnEnSetfocusEdit()
{
m_editSel.SetSel(0,-1,TRUE);
}不过,这只有当编辑框获得焦点时才会变,如果焦点已在它在面的话,要实现任意时侯单击之后选中,可以通过重载CEdit类,然后重载
void CMyEdit::OnLButtonUp(UINT nFlags, CPoint point)
{
SendMessage(WM_LBUTTONDBLCLK,0,0);
CEdit::OnLButtonUp(nFlags, point);
}
就行了。