Move the Caret to a line
I've tried quite a few different approaches, to moving the Caret at the beginning of a specified line, but I can only seem to get it to work for one line, and for the rest, it moves to random places in that line. How would I go about moving the caret to the beginning of a line?
I'm using EM_SETSEL to set its location.
I've tried using EM_LINELENGTH to get the number of TCHAR's in each line, then adding one to move to the next line, and repeat for each line until I reach my designated line, but this only really works for the second line, and no more lines than that.
The EM_LINEINDEX message may help.
Amongst all that researching of the messages on the MSDN, I had missed the one which I was looking for.
Well I get it to go to the right line, but now when I open up my dialog box to get the line number, selecting the line doesnt work. It works perfectly fine when I dont open up the dialog box. Why is this?
Here is the code of my function:
lineNum = DialogBox(GetModuleHandle(0), MAKEINTRESOURCE(IDD_GOTO), m_hTextBox, GoToProc);
}while(lineNum > SendMessage(m_hTextBox, EM_GETLINECOUNT, 0, 0) || lineNum < 0);
if (lineNum == 0) // If user pressed cancel
lineNum--; // Make EM_SETSEL select the right line.
int pos = SendMessage(m_hTextBox, EM_LINEINDEX, lineNum, 0);
SendMessage(m_hTextBox, EM_SETSEL, pos, pos);