Shoutbox

[HELP] Get cursor position (X, Y) & set window position (X, Y) - 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: [HELP] Get cursor position (X, Y) & set window position (X, Y) (/showthread.php?tid=83733)

[HELP] Get cursor position (X, Y) & set window position (X, Y) by SmokingCookie on 05-15-2008 at 04:11 PM

Hi,

Another question:

I'd like to know whether there's a way to get the cursor's position (the flickering vertical "line") in a chat window, and setting a window's position to the cursor's (like Plus! does when "/" is the 1st character).

I have once read about the 2nd, but never about the 1st..

Greetz..


RE: [HELP] Get cursor position (X, Y) & set window position (X, Y) by Matti on 05-15-2008 at 04:21 PM

Where do you mean? In the chat window, you have the history area (where the sent and received messages are) and the typing area (where you type your messages).

For the first one, there are ChatWnd.HistoryText_GetCurSelStart() and ChatWnd.HistoryText_GetCurSelEnd() functions which let you get the current selection in the history. However, it is not possible to set the selection there.
For the second one, you can use ChatWnd.EditText_GetCurSelStart() and ChatWnd.EditText_GetCurSelEnd() to retrieve the selection and use ChatWnd.EditText_SetCurSel(Start, End) to set it.

Note: if the start and end of a selection are equal, it means that the typing cursor is at that position and has nothing selected. That's what your flickering vertical line is. ;)

Although I don't really understand what you mean with "setting the window's position to the cursor's"... :-/


RE: [HELP] Get cursor position (X, Y) & set window position (X, Y) by SmokingCookie on 05-15-2008 at 04:29 PM

What  mean is: Plus! opens a window with the commands at the cursor's position in the typing area, as soon as "/" is typed (as long as its character index ix 0). I'd like to do the same (using OnEvent_ChatWndEditKeyDown). Here for, I need the cursor's X and Y position. Is there a way to get it? I think it'd be something like this:

code:
Interop.Call(DllName,"GetCursorPos",ChatWnd.Handle);
//DllName is probably the name of some system DLL like User32.dll or something


RE: [HELP] Get cursor position (X, Y) & set window position (X, Y) by Volv on 05-15-2008 at 04:31 PM

GetCursorPos refers to the position of the mouse pointer, not the writing cursor thingy.


RE: [HELP] Get cursor position (X, Y) & set window position (X, Y) by SmokingCookie on 05-15-2008 at 04:33 PM

Okay... Now I need the writing cursot's position. Is there a way to get it?


RE: [HELP] Get cursor position (X, Y) & set window position (X, Y) by Matti on 05-15-2008 at 04:38 PM

Actually, it's very tough to do this. You'd have to know the font face and font size and the size of the typing area itself to calculate the size of the text and find the position of the typing cursor. Plus! does this pretty good with the Quick Emoticons menu, but there are no script features available to achieve this with a simple Plus! script.

Maybe you should talk to Patchou and ask how you could do it? :P


RE: [HELP] Get cursor position (X, Y) & set window position (X, Y) by SmokingCookie on 05-15-2008 at 04:42 PM

Okay :P

Would Plus! call a DLL to locate the writing cursor? (Sorry, but contacting Patchou is the last thing I would do.. To prevent me from flooding his mailbox :P )


RE: [HELP] Get cursor position (X, Y) & set window position (X, Y) by Matti on 05-15-2008 at 05:53 PM

quote:
Originally posted by SmokingCookie
Would Plus! call a DLL to locate the writing cursor?
I highly doubt it. I think the way Plus does it, is by calculating the bounding box of the text before the cursor using the font face and size and then use that to find out where to draw the pop-up. Only problem is that a script can't get Messenger's font face and size, or the size of the typing box (for word wrapping).
RE: [HELP] Get cursor position (X, Y) & set window position (X, Y) by SmokingCookie on 05-15-2008 at 07:25 PM

Hmm.. So you think I should figure out how big the rectangle of the typing area is (this data is probably somewhere not in the registry..), do let some maths do their job and set the window's position?


RE: [HELP] Get cursor position (X, Y) & set window position (X, Y) by matty on 05-15-2008 at 07:59 PM

To get the Caret position you can use the GetCaretPos. Now this is in relation to the Caret position in the text box you are typing in now the screen.

The IMConvInputHeight2 key located in the registry (HKEY_CURRENT_USER\Software\Microsoft\MSNMessenger\PerPassportSettings\1959057673) tells you the height of the input box.

code:
var prePOINT = Interop.Allocate(8);
var newPOINT = Interop.Allocate(8);

MsgPlus.AddTimer('x', 100);

function OnEvent_Timer(sTimerId) {
    Interop.Call('user32', 'GetCaretPos', newPOINT);
    if ( newPOINT.ReadDWORD(0) !== prePOINT.ReadDWORD(0) || newPOINT.ReadDWORD(4) !== prePOINT.ReadDWORD(4) ) {
        Interop.Call('kernel32', 'RtlMoveMemory', prePOINT, newPOINT, 8);
        Debug.Trace('x : '+newPOINT.ReadDWORD(0)+'\ty: '+newPOINT.ReadDWORD(4));
    }
    MsgPlus.AddTimer('x', 100);
}

RE: [HELP] Get cursor position (X, Y) & set window position (X, Y) by SmokingCookie on 05-15-2008 at 08:07 PM

Right... Your piece of code looks quite.. advanced and difficult to me... I have learnt, though, that Plus! places the command helper at one specific position (not next to the cursor), so in fact I only have to get the width and height of the inpt area..

But then there's part 2 of my question: how to alter a window's position?


RE: [HELP] Get cursor position (X, Y) & set window position (X, Y) by matty on 05-15-2008 at 09:16 PM

What you are trying to do is going to be imperfect at best because it is impossible to get the exact position of the controls unless you use the MSNCore.dll file to read the DirectUIHWND control to find the exact positions.


RE: [HELP] Get cursor position (X, Y) & set window position (X, Y) by SmokingCookie on 05-16-2008 at 02:55 PM

Okay.. I am going to try and use you code anyway.. But I need some function to set a window's position. I know it's in some system DLL, because I have once read about it, but I just don't know where to find it. Is there anyone who does?


RE: [HELP] Get cursor position (X, Y) & set window position (X, Y) by mynetx on 05-16-2008 at 03:10 PM

You are talking about MoveWindow ;)
Use it like
Interop.Call('user32', 'MoveWindow', /*....its parameters here */ );


RE: [HELP] Get cursor position (X, Y) & set window position (X, Y) by SmokingCookie on 05-16-2008 at 03:13 PM

Yes :D Thanks lads :D

EDIT::

I already knew how to use it (doesn't happen ofetn :P ), but thanks anyway ;)