Shoutbox

Cursor Position in Plus text boxes - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Cursor Position in Plus text boxes (/showthread.php?tid=73391)

Cursor Position in Plus text boxes by win_crook on 04-07-2007 at 05:47 PM

Is there any way I can get the position of the text cursor in a text box in a plus interface?

I need to insert some text at the current cursor position instead of at the end of the box which is the way I'm currently doing it.

Thanks,
David


RE: Cursor Position in Plus text boxes by Patchou on 04-07-2007 at 06:04 PM

you can send the EM_GETSEL message. In version 4.21, some new functions have been added to add more support for edit controls.


RE: Cursor Position in Plus text boxes by win_crook on 04-07-2007 at 06:21 PM

Would it be possible for you to give me some guidance on how to do this please? Maybe just a little example to get me started.


RE: RE: Cursor Position in Plus text boxes by felipEx on 04-07-2007 at 08:48 PM

quote:
Originally posted by Patchou
you can send the EM_GETSEL message. In version 4.21, some new functions have been added to add more support for edit controls.

Hi Patch.
you would have to consider the use of <MaxLength>   :P

it can be possible with API.
code:
var EM_LIMITTEXT = 0xC5;
Interop.Call("user32", "SendMessageW", PlusWnd.GetControlHandle("mytxt"), EM_LIMITTEXT, 11 /* or new maxlength value */ , 0);

RE: Cursor Position in Plus text boxes by win_crook on 04-08-2007 at 12:00 PM

Well I've figured out the EM_GETSEL message and it's working fine now. I'm onto the string processing part now, and I'm getting this error:

quote:
Error: Object doesn't support this property or method.
       Line: 40. Code: -2146827850.


This is the code, the middle line is line 40:
code:
var text = Wnd.GetControlText("NameEdit");
var firstHalf = text.substring(0, Start);
var secondHalf = text.substring(Start, before.length);


I'm assuming it's talking about the substring method, but I don't see why it's saying it's unsupported... any ideas?

Thanks,
David
RE: Cursor Position in Plus text boxes by effection on 04-08-2007 at 12:32 PM

what is $Start defined as?


RE: Cursor Position in Plus text boxes by win_crook on 04-08-2007 at 12:36 PM

Here is the code that defines start:

code:
var EM_GETSEL = 0xB0;
var EM_SETSEL = 0xB1;
var Start = Interop.Allocate(32);
Interop.Call("user32", "SendMessageW", Wnd.GetControlHandle("NameEdit"), EM_GETSEL, Start, 0);


RE: Cursor Position in Plus text boxes by matty on 04-08-2007 at 02:44 PM

quote:
Originally posted by win_crook
Here is the code that defines start:
code:
var EM_GETSEL = 0xB0;
var EM_SETSEL = 0xB1;
var Start = Interop.Allocate(32);
Interop.Call("user32", "SendMessageW", Wnd.GetControlHandle("NameEdit"), EM_GETSEL, Start, 0);


When you are allocating memory to a variable you cannot simply reference the variable itself. In this case the value you are trying to read is a DWORD.

You need to replace:
code:
var text = Wnd.GetControlText("NameEdit");
var firstHalf = text.substring(0, Start);
var secondHalf = text.substring(Start, before.length);


With this
code:
var text = Wnd.GetControlText("NameEdit");
var firstHalf = text.substring(0, Start.ReadDWORD(0));
var secondHalf = text.substring(Start.ReadDWORD(0), before.length);


And where does before come into play?

Also why are you allocating 32 bytes of memory to Start? It should be 4.
RE: Cursor Position in Plus text boxes by win_crook on 04-08-2007 at 02:49 PM

Thanks a lot for that :D... the before doesn't come into play, I forgot to change it to text for this example. It's all working fine now.


RE: Cursor Position in Plus text boxes by Felu on 04-08-2007 at 03:41 PM

quote:
Originally posted by effection
$Start
He never used the variable $Start. It was Start. Please don't confuse with it. This is not php that you'll need $ for a variable. This is JScript.