What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [?] Detecting when a Plus! Window is closed

Pages: (2): « First « 1 [ 2 ] Last »
[?] Detecting when a Plus! Window is closed
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: [?] Detecting when a Plus! Window is closed
Well, there is a way to create a new event handler function in run-time, but it's really nasty coding. I've been experimenting with this some time ago, but it's just plain ugly. Nevertheless, if it can help you or others, here it is:
Javascript code:
function CreateTheWindow( PlusWnd ) {
    var sWndId;
    // Code to retrieve the selected window ID goes here
 
    // Assign a new event in the global scope
    // Unfortunately, eval() is needed for this
    eval( "On"+sWndId+"Event_Destroyed = OnCreatedWindowEvent_Destroyed" );
    // Now the registered events have to be reloaded
    // We'll be loading an empty JScript file to trigger the reloading
    MsgPlus.LoadScriptFile("blank.js");
    // Now that everything is set, create the window
    var oWnd = MsgPlus.CreateWnd( "Interfaces.xml", sWndId );
}
 
// We'll make the new event handlers call this function
function OnCreatedWindowEvent_Destroyed( PlusWnd, ExitCode ) {
    // Code goes here
}

I've tried many things already, but this is the best that I could get.
  • In a JScript environment, global variables cannot be assigned by a variable name through normal code. In JavaScript on the contrary, there is the window object which controls all globally defined variables, allowing developers to use window['name'] to define a new global. The same thing goes for many other languages such as PHP, where you can use $$varname to create variables by a variable name. Unfortunately all of this can't be done in Plus! scripting without eval()...
  • The created global function won't be registered as event handler right away either. In order for Plus! to re-register the global functions, another script file has to be loaded into the script using MsgPlus::LoadScriptFile.
So yes, in order to achieve this in a better way we'll need some changes in Plus! scripting itself. Here are my suggestions:
  • Event handlers for all script windows (see CookieRevised's reply to [?] Detecting when a Plus! Window is closed).
  • An OOP approach for event handlers:
    Javascript code:
    // DEMONSTRATION CODE
    // This does not actually work at the time of writing!
    var fEvent = function( PlusWnd, ExitCode ) {
        // Code goes here
    }
    PlusWnd.AddEvent( 'Destroyed', fEvent );

    This would not only allow new events to be created in run-time, but also add more than one handler to a single event. This would make it so much easier to manage the code: it would make it possible to put all code for one feature in separate script files instead of having to mix all code for the handlers in one event.
What do you think? :P

This post was edited on 10-17-2009 at 08:56 AM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
10-17-2009 08:55 AM
Profile E-Mail PM Web Find Quote Report
Pages: (2): « First « 1 [ 2 ] Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On