caret repositions itself

This is a discussion on caret repositions itself within the Windows Programming forums, part of the Platform Specific Boards category; I am trying to manipulate caret position in an edit control using Winapi SetCaretPos() function. When the user clicks on ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Location
    Delhi, India
    Posts
    59

    caret repositions itself

    I am trying to manipulate caret position in an edit control using Winapi SetCaretPos() function. When the user clicks on a button, the caret in the edit box advances a certain number of pixels forward(its like inserting a blank automatically). Till here everything goes fine, and the caret blinks at its new position, but when I try to write anything in the edit box now, it goes back to the previous place before the automatic space. Any suggestions on how can I skip certain space in edit box?
    A few lines of code:
    Code:
    length=GetWindowTextLength(Fill_Blanks_Enter_Question_Edit);
    SetFocus(Fill_Blanks_Enter_Question_Edit);
     GetCaretPos(&Cursor_Pos);            //Cursor_Pos is of type LPPOINT
     SetCaretPos(Cursor_Pos.x + 50,Cursor_Pos.y);
    The caret flashes at the right position, but I am not able to write at that position.
    Last edited by Salem; 07-26-2011 at 03:14 AM. Reason: line wrapping

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Actually it's returning to the end of the text buffer and adding text there.
    Moving the typing caret beyond the end of the text does NOT add spaces...
    If you want to add spaces, you have to add spaces to the end of the text buffer.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Location
    Delhi, India
    Posts
    59
    @Commontater
    I got your point, but can't I insert spaces using code?, like on press of a button, the caret should move ahead as if the user manually entered the space. Is it difficult to implement or not possible at all?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    That's what Tater is suggesting you do, add spaces using code.

    I suppose you might do something like SendInput with a space, or if you can access the text field of your edit box, then just add a space to the end of it.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by gaurav_13191 View Post
    @Commontater
    I got your point, but can't I insert spaces using code?, like on press of a button, the caret should move ahead as if the user manually entered the space. Is it difficult to implement or not possible at all?
    It's easy enough... Look up the various messages you can send to an edit control... everything you need is there.

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by tabstop View Post
    That's what Tater is suggesting you do, add spaces using code.

    I suppose you might do something like SendInput with a space, or if you can access the text field of your edit box, then just add a space to the end of it.
    SendInput is dangerous in this situation since it only works with the foreground window... i.e. the button his user just clicked.

  7. #7
    Registered User
    Join Date
    Dec 2010
    Location
    Delhi, India
    Posts
    59
    Ok I solved the above problem of inserting text.. but I have got another issue that I am unable to position the caret at the end position after updating my edit control text. It positions itself at the beginning, I searched for this on the internet and found EM_SETSEL message to place it at desired position. But here the problem arises is that the text behind the current caret position is highlighted which I don't need. I just want that the caret places itself at the correct position after I insert my blank/space. Any suggestions?

  8. #8
    Registered User
    Join Date
    Dec 2010
    Location
    Delhi, India
    Posts
    59
    I resolved the issue.. no need to answer.. thanks for all the answers..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rich Edit Control - Get And Set Caret Position?
    By Charles01 in forum Windows Programming
    Replies: 1
    Last Post: 12-05-2005, 09:26 AM
  2. Move the Caret to a line
    By TheDan in forum Windows Programming
    Replies: 3
    Last Post: 08-07-2005, 12:59 PM
  3. How to show Blinking caret?
    By loko in forum C Programming
    Replies: 2
    Last Post: 07-13-2005, 02:53 AM
  4. The Caret
    By Rez in forum Windows Programming
    Replies: 3
    Last Post: 11-25-2002, 07:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21