I think something like this would work. I am at work and cannot test it but this is what it does
It will change the title of the window if it isn't in the foreground and restores it when the window is brought forward. There is already a glitch I can tell of without even running it and that would be if the contact changes their name then the script wont update it and the new title will be visible. But this is something that could be worked upon.
jscript code:
var oChatWnds = { };
var oChatWnds_WinTitle = { };
function OnEvent_ChatWndSendMessage( pChatWnd, sMessage ) {
oChatWnds[ pChatWnd.Handle ] = sMessage;
}
function OnEvent_ChatWndDestroyed( pChatWnd ) {
delete oChatWnds[ pChatWnd.Handle ];
delete oChatWnds_WinTitle[ pChatWnd.Handle ];
}
function OnEvent_ChatWndReceiveMessage( pChatWnd, sOrigin, sMessage, nMessageKind ) {
// check if the event is thrown because our message was recieved in the chat history
if ( oChatWnds[pChatWnd.Handle] !== sMessage ) {
// check if the current window isn't the chat window
if ( Interop.Call( 'user32', 'GetForegoundWindow' ) !== pChatWnd.Handle ) {
// get the current title to restore once the window has been brought forward
var intTitleLength = Interop.Call( 'user32', 'GetWindowTextLengthW', pChatWnd.Handle );
var lpszTitle = Interop.Allocate( intTitleLength );
Interop.Call( 'user32', 'GetWindowTitleW', pChatWnd.Handle, lpszTitle, intTitleLength );
oChatWnds_WinTitle[ pChatWnd.Handle ] = lpszTitle.ReadString( 0 );
// create a string to hold the new title
var lpszNewTitle = MsgPlus.RemoveFormatCodes( Messenger.MyName )+' : ';
// loop through all of the contacts
for( var oContact = new Enumerator( pChatWnd.Contacts ); !oContact.atEnd(); oContact.moveNext() ) {
// concatenate a string for all participants
lpszNewTitle += MsgPlus.RemoveFormatCodes( oContact.item().Name ) + ( oContact.atEnd() ? '', ', ' );
}
// set the new title for the window
Interop.Call( 'user32', 'SetWindowTextW', pChatWnd.Handle, lpszNewTitle );
// use a timer to verify when the window is brought to the front
MsgPlus.AddTimer( pChatWnd.Handle, 100 );
}
}
}
function OnEvent_Timer( sTimerId ) {
// check if the window is the front window
if ( Interop.Call( 'user32', 'GetForegroundWindow' ) !== sTimerId ) {
// since the window is still in the background lets make sure it still exists before readding the timer for it
if ( Interop.Call( 'user32', 'IsWindow', sTimerId ) ) MsgPlus.AddTimer( sTimerId, 100 );
// exit the function
return;
}
// set the old window title now that the window is brought forward
Interop.Call( 'user32', 'SetWindowTextW', sTimerId, oChatWnds_WinTitle[ sTimerId ] );
}