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
}
}