Shoutbox

function OnGetScriptMenu - ChatWnd - 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: function OnGetScriptMenu - ChatWnd (/showthread.php?tid=84709)

function OnGetScriptMenu - ChatWnd by Suxsem on 07-07-2008 at 12:12 PM

Hi!
The function OnGetScriptMenu has a only Location Parameter...but, can i know the Chat Windows that open Menù if Menù isn't open by contact list?
I thought to find the handle of the active window and find the associated Chat Windows...but I don't know to do this :D
thank for all, bye!


RE: function OnGetScriptMenu - ChatWnd by Matti on 07-07-2008 at 12:17 PM

Unfortunately, there isn't a way that I know of which allows you to get the ChatWnd where the menu is being opened. I think it's something Plus! is missing, or else it's because there's some kind of restriction...

Someone ask Patchou about this? :P


RE: function OnGetScriptMenu - ChatWnd by Suxsem on 07-07-2008 at 12:20 PM

ok...thank


RE: function OnGetScriptMenu - ChatWnd by matty on 07-07-2008 at 04:08 PM

Just use the Win32 API GetForegroundWindow this will return the handle of the window then you can iterate through the current open chat windows to get the Plus! ChatWnd object.

code:
for ( var oChatWnd = new Enumerator( Messenger.CurrentChats ); !oChatWnd.atEnd(); oChatWnd.moveNext() ) {
    if ( oChatWnd.item().Handle === Interop.Call( 'user32', 'GetForegroundWindow' ) {
        return oChatWnd.item();
    }
}

RE: function OnGetScriptMenu - ChatWnd by Suxsem on 07-08-2008 at 11:09 AM

Thank for replay!
But, if I use the function:

code:
for ( var oChatWnd = new Enumerator(Messenger.CurrentChats); !oChatWnd.atEnd(); oChatWnd.moveNext() ) {
    if ( oChatWnd.Handle === Interop.Call('user32', 'GetForegroundWindow' )) {
        Debug.Trace("ok")
        return oChatWnd;
    }
}

"ok" never display in debug windows!

RE: function OnGetScriptMenu - ChatWnd by Matti on 07-08-2008 at 11:39 AM

Ah, I see. Matty didn't test his code properly, and thus he mixed up a few things. :)

This should work fine:

code:
function GetChatWnd() {
    for ( var e = new Enumerator(Messenger.CurrentChats); !e.atEnd(); e.moveNext() ) {
        var oChatWnd = e.item();
        if ( oChatWnd.Handle === Interop.Call('user32', 'GetForegroundWindow' ) {
            return oChatWnd;
        }
    }
    return false;
}
And an implementation example:
code:
function OnGetScriptMenu( nLocation ) {
    if( nLocation === MENULOC_CHATWND ) {
        var oChatWnd = GetChatWnd();
        //Do anything you want with the ChatWnd object here...
        //Maybe you need some error handling in case oChatWnd is false,
        //when the foreground chat window couldn't be found.
    } else {
        //Contact list or mobile chat window
    }
}

RE: function OnGetScriptMenu - ChatWnd by Suxsem on 07-08-2008 at 11:41 AM

ok...this function is correct:

code:
function chatAttuale(){
var Windows = Messenger.CurrentChats;
var e = new Enumerator(Windows);
for(; !e.atEnd(); e.moveNext())
{
    var ChatWindow = e.item();
    if ( ChatWindow.Handle == Interop.Call('user32', 'GetForegroundWindow' )) {
       return ChatWindow
     }
}
}
thank for all, bye!
RE: function OnGetScriptMenu - ChatWnd by matty on 07-08-2008 at 01:13 PM

quote:
Originally posted by Mattike
Ah, I see. Matty didn't test his code properly, and thus he mixed up a few things. :)

code:
var oChatWnd = e.item();

Oops haha

Updated the previous post... thanks Matti it has been awhile since I have written Plus! Scripts... I should get back to it...