You could assign a control variable (not a string) for your edit controls and then use SetSel as you tried, or you can do it like this:
((CEdit*)GetDlgItem(ID_whatever_it_is))->SetSel( start. end );
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am making a Visual Studio MFC C++ App, and I am having a (hopefully) small problem.
I have an Edit Control text box with ID txtInputBox, and it has a value C-String variable m_inputText assigned to it. After I do a SetDlgItemText(txtInputBox, L"Hello World"); the cursor moves to the front of the text, before the 'H'. How would I get the cursor to be at the end (after the 'd') right after doing a SetDlgItemText?
I read of a SetSel method, but don't know how to implement it if that's the right one.
What I have is:
someDlg::someFunction() //this is used in an EN_CHANGE event
{
//some logic stuff to get a result string
SetDlgItemText(txtInputBox, L"Hello World");
//need it to set the cursor to the end
//I tried these, but it didn't recognize (expression must have class type?). doesn't work
//txtInputBox.SetSel(0, -1);
//txtInputBox.SetSel(-1);
}
void someDlg::EnChangetxtinputbox()
{
someFunction();
}
You could assign a control variable (not a string) for your edit controls and then use SetSel as you tried, or you can do it like this:
((CEdit*)GetDlgItem(ID_whatever_it_is))->SetSel( start. end );