EM_SETSEL The EM_SETSEL message selects a range of characters in an edit control. You can send this message to either an edit control or a rich edit control.To send this message, call the SendMessage function with the following parameters. SendMessage( (HWND) hWnd, // handle to destination window EM_SETSEL, // message to send (WPARAM) wParam, // starting position (LPARAM) lParam // ending position ); Parameters wParam Specifies the starting character position of the selection. lParam Specifies the ending character position of the selection. Return Values This message does not return a value. Res The start value can be greater than the end value. The lower of the two values specifies the character position of the first character in the selection. The higher value specifies the position of the first character beyond the selection. The start value is the anchor point of the selection, and the end value is the active end. If the user uses the SHIFT key to adjust the size of the selection, the active end can move but the anchor point remains the same.If the start is 0 and the end is –1, all the text in the edit control is selected. If the start is –1, any current selection is deselected. Edit controls: The control displays a flashing caret at the end position regardless of the relative values of start and end.
若是SetFocus第二个编辑框
然后发EM_SETSEL到第二个编辑框
The EM_SETSEL message selects a range of characters in an edit control. You can send this message to either an edit control or a rich edit control.To send this message, call the SendMessage function with the following parameters. SendMessage(
(HWND) hWnd, // handle to destination window
EM_SETSEL, // message to send
(WPARAM) wParam, // starting position
(LPARAM) lParam // ending position
);
Parameters
wParam
Specifies the starting character position of the selection.
lParam
Specifies the ending character position of the selection.
Return Values
This message does not return a value. Res
The start value can be greater than the end value. The lower of the two values specifies the character position of the first character in the selection. The higher value specifies the position of the first character beyond the selection. The start value is the anchor point of the selection, and the end value is the active end. If the user uses the SHIFT key to adjust the size of the selection, the active end can move but the anchor point remains the same.If the start is 0 and the end is –1, all the text in the edit control is selected. If the start is –1, any current selection is deselected. Edit controls: The control displays a flashing caret at the end position regardless of the relative values of start and end.
而且我对对话框设定了ON_KEYDOWN ,连加速键都加上去了,但我在编辑框输入完后按回车仍是毫无反应,该如何是好呢,我急死了,请快救救我吧。
BOOL CDlg1::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_KEYDOWN)
if(int(pMsg->wParam) == VK_RETURN)
{
((CEdit*)GetDlgItem(ID_EDIT2))->SetFocus();
((CEdit*)GetDlgItem(ID_EDIT2))->SetSel(0,-1);
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}这里实现的是只要你回车就选种EDIT2的全部文本,你可以对其进行
适当修改。