CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2003
    Location
    SA
    Posts
    147

    CaretPos vs. CharacterPos

    I am trying to figure out a way to "insert" text in an editbox, but doing this programatically, using the current position of the editbox.

    The MSDN states that CaretPos can be used to determine the current position of the Caret, eg.

    POINT ptChr;
    ptChr = m_edit_Action.GetCaretPos();

    so in turn

    ptChr.x <- will give me the current caret position of the editbox, but unfortunately the .x member of this current position points to an actual coordinate.

    How would I know where in the editbox the caretpos is ... so that I could manipulate the insertion of text as follows ...

    CString strInsertText("");
    m_edit_Action.GetWindowText(strInsertText);

    strInsertText.Insert(<Get current character position>, "INSERT TEXT");

    m_edit_Auction.SetWindowText(strInsertText);



    Actual text of the editbox ->

    ABC<The Caret is currently at the postion, after character 2, and before character 3>DEFG

    an the GetCaretPos() members returns 65 (which is actually pixels, or the actual x coordinate of the caret).

    [b]So how will I programarically be able to know that the caret is currently between character 2 and 3 ... ??

    Thanx in advance ...

    xIRC
    Last edited by xIRC; September 26th, 2003 at 11:18 AM.

  2. #2
    Join Date
    Mar 2003
    Location
    SA
    Posts
    147

    Understandable ...

    Does anyone maybe know anything about caret pos, or is this not the caret pos I should be concerned with, rather the keyboard cursor pos (I think this is called the caret pos, I'm not english, it's my second language, so I don't understand really in my home language what caret pos means, entirely) ...

    So this is the keyboard cursor blinking in a editbox?

  3. #3
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940
    In an edit box, the GetSel function returns the start & end character of the selection. (I.e. CEdit).

    If the start & end are the same then the caret will be between start and start-1 if you see what I mean.

    Therefore if start = 0 and end = 0 then the caret will be at the start, otherwise if start = 2 and end = 2 then the caret will be between characters 1 and 2 in the edit.

    You can call SetSel on CEdit to set the caret position.

    For your information :

    The caret is a shared resource in Windows which windows use to display cursor position. It is not linked to any character etc, it is positioned manually using coordinates (see SetCaretPos and CreateCaret).

    Hope this helps,

    Darwen.

  4. #4
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940
    Oh and as an aside : don't muck around with the caret position manually (i.e. CreateCaret and SetCaretPos) unless you really know what you're doing !

    Unless you're doing a clever CEdit (like the one I wrote which will do Unicode characters - i.e. characters in any language - in non-unicode builds) then don't bother with these functions.

    CEdit will take care of all the caret positions for you.

    Darwen.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured