IonicWind Software

IWBasic => General Questions => Topic started by: Andy on March 11, 2015, 03:56:00 AM

Title: Edit box cursor position
Post by: Andy on March 11, 2015, 03:56:00 AM
Hi,

I've been wondering for a good time now is it posible to place the cursor at the end of some text 
in an edit box?

Example:

I create a simple window.
I have an edit box control
The edit box has the word "IWBasic" in it on creation.

If I set the focus on the edit box the cursor goes before the "I" in IWBasic.
Can you position the cursor after the letter "c" in IWBasic when it gets the focus?

Just curious to see if it can be done, think it might help when editing many edit boxes with text in them.

Thanks,
Andy.
:)


Title: Re: Edit box cursor position
Post by: Egil on March 11, 2015, 05:27:09 AM
Try this:


'
'------------------------------------------------------------------------------
' subroutine to easily append text in an edit control
' by Paul Turley: http://www.ionicwind.com/forums/index.php/topic,3174.0.html
'
' id = the id of the edit control
'------------------------------------------------------------------------------
'
CONST WM_GETTEXTLENGTH = 0xE
Sub AppendEdit(window win,int id,string text,int addNL)
int _textlen:_textlen =SendMessage(win, WM_GETTEXTLENGTH,0,0,id)
ControlCmd win, id, @EDSETSELECTION, _textlen, _textlen
if(addNL)
ControlCmd win, id, @EDREPLACESEL, text + "\n"
else
ControlCmd win, id, @EDREPLACESEL, text
endif
RETURN
ENDSUB


Calling  with an empty string will place the cursor at the end of the edit control.


Good luck!

Egil
Title: Re: Edit box cursor position
Post by: Andy on March 11, 2015, 06:28:49 AM
Thanks Egil and of course to Paul,

Yes, doing this:

       AppendEdit(dy,p1,"",0)
       SetFocus dy,p1

Where dy is the window, and p1 is the edit control.

Works great and looks professional!

Thanks to both of you!
Andy.
:)
Title: Re: Edit box cursor position
Post by: Brian on March 11, 2015, 10:10:52 AM
Egil,

Been messing, and came up with this. Does it in two lines, three if you add the SETFOCUS:

WINDOW win

OPENWINDOW win,0,0,300,200,0x80CB0080,0,"Caption",&wHandle
   CONTROL win,@EDIT,"IWBasic is Great!",35,70,186,26,0x50800080,10
   SETFOCUS win,10
   INT length=CONTROLCMD win,10,@EDGETLINELENGTH,-1
   CONTROLCMD win,10,@EDSETSELECTION,length,length

WAITUNTIL IsWindowClosed(win)

SUB wHandle(),INT
   SELECT @MESSAGE
CASE @IDCREATE
   CENTERWINDOW win
CASE @IDCLOSEWINDOW
   CLOSEWINDOW win
ENDSELECT
RETURN 0
ENDSUB

Brian
Title: Re: Edit box cursor position
Post by: Egil on March 11, 2015, 02:07:41 PM
That's almost the same as Paul once suggested.
The SUB I posted was copied from my SerialComms Terminal program.
Had to put in the extras to cope with the behaviour of different kinds of modems, to get the logfiles right when woorking with multiline editcontrols, echo on or off in the modem, local echo on or off. And some modems always return an extra newline character.
I usuall make my subs so they can be reused in other applications, and sometimes they look some "strange" to others.... :D

Regards,
Egil