Thread: Move the Caret to a line

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    30

    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.

  2. #2
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    The EM_LINEINDEX message may help.

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    30
    =|

    Amongst all that researching of the messages on the MSDN, I had missed the one which I was looking for.

    Thanks

  4. #4
    Registered User
    Join Date
    Apr 2005
    Posts
    30
    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:
    Code:
    int lineNum;
    	do
    	{
    		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
    		return;
    
    	lineNum--; // Make EM_SETSEL select the right line.
    
    	int pos = SendMessage(m_hTextBox, EM_LINEINDEX, lineNum, 0);
    	SendMessage(m_hTextBox, EM_SETSEL, pos, pos);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ASM beginner gets 24 compiler errors on hello world...
    By Desolation in forum Tech Board
    Replies: 12
    Last Post: 06-16-2007, 10:21 PM
  2. Replies: 19
    Last Post: 05-30-2007, 05:47 PM
  3. Line Drawing Algorithm
    By Axpen in forum Game Programming
    Replies: 15
    Last Post: 08-01-2005, 06:30 PM
  4. Formatting Output
    By Aakash Datt in forum C++ Programming
    Replies: 2
    Last Post: 05-16-2003, 08:20 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM