PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Martin Francom on December 18, 2009, 11:19:00 PM

Title: Another TextBox Question
Post by: Martin Francom on December 18, 2009, 11:19:00 PM
Is there a way to determine the current position of the cursor in a TextBox?

Title: Re: Another TextBox Question
Post by: Paul Squires on December 19, 2009, 12:12:14 AM

   Local nStartPos As Long
   Local nEndPos   As Long
   
   SendMessage hWndControl, %EM_GETSEL, VarPtr(nStartPos), VarPtr(nEndPos)


http://www.powerbasic.com/support/pbforums/showthread.php?p=330746#post330746
Title: Re: Another TextBox Question
Post by: Martin Francom on December 19, 2009, 01:19:54 AM
Paul,
   I am not quite sure I understand.

Lets say I have a TextBox with these charactes in it:

     [1234567890]           (brackets [] just symbolize the textbox)

and lets say the cursor is on the 6 which happens to be in the sixth position the the textbox. Note that no text is highlighted.  If a person was to press a key the character would insert right  after the 6.   So, when I use the SendMessage which of those variables is going to tell me the location of the cursor?

Can you correct this for me:


    local CurLoc as long   ' Cursor Location in TextBox

    CurLoc =  SendMessage hWndControl, %EM_GETSEL, VarPtr(nStartPos), VarPtr(nEndPos)

Title: Re: Another TextBox Question
Post by: Martin Francom on December 19, 2009, 05:45:31 AM
A fellow on the PB forum help me understand.  I think I have it now. From his example program.

I see that when no text is highlight (selected) then the
nStartPos and nEndPos are the same value that value being
the current location of the cursor.  And when some text
is highlighted then the values are different but the nStartPos
is always the location of the cursor where text insertion would
begin.

So if I am interested in the location of the cursor then the
value I need to use is the nStartPos