Shoutbox

Global Window-handler possible? - 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: Global Window-handler possible? (/showthread.php?tid=84111)

Global Window-handler possible? by RdeWilde on 06-03-2008 at 10:20 AM

Hello,

I'm trying to create a function for handling my windows globally, this means all events should be handover to this function. But now I got this far and took a look at the documentation, I noted there's no global window event? Just with the WindowId in it.

I'd like to use OnWindowEvent_CtrlClicked, where Window stands for all windows. Is there any way to achieve this? Thanks.

Edit: Here's some of the code i'd like to implement.

code:
cWindow = function(oCmds)
{    if (!oCmds) oCmds = {};

    this.__coll = Array();        // Collection windows
    this.__cmds = oCmds;
   
    this.openWindow = function(sFile, sName, sOptions)
    {    if (!this.__coll[sName])
            this.__coll[sName] = MsgPlus.CreateWnd(sFile, sName, sOptions);
           
        // Maybe there's a way to add the handling here?       
    };
   
   
    this.handleWindow = function(sWindow, sCtrlId)
    {    // Handling here
        if (this.__cmds[sWindow][sCtrlId]())
            return true;           
        else
            return false;
    }
   
   
    this.closeWindow = function(sName)
    {    this.__coll[sName] = null;
    };   
}

Calling function:
code:
var oOS;

cOutlookStatus = function(oSetting)
{    this.__register     = new cRegister();
    this.__timer        = new cTimer();
    this.__window        = new cWindow(
    {'__OS_wndCalender':
        {'__OS_btnStatusSave' : function()
            {    MsgPlus.DisplayToast('Made IT!');
            }
        }
    }
    );
   
    with (oSetting)
    {
        this.version    = version || 1.09;       
    }
};
Edit: Spacing is removed? :S
RE: Global Window-handler possible? by markee on 06-03-2008 at 10:56 AM

OnWindowEvent_CtrlClicked is for Plus! windows that you have created using MsgPlus.CreateWnd.

You'll have to get the handle for the chat window and use a windows DLL to detect when a control is clicked in a chat window however. (May I ask why you need this anyway?).

Furthermore, you have REALLY complicated things with chat windows.  You can itterate through them using Messenger.CurrentChats which will save on memmory and be easier for everyone to understand (and more straightforward for yourelf as well).

You can also get the handle of a window with a contact that is currently open already by using Messenger.OpenChat.

I highly recomend that you look at other scripts.  I find your code unnecessarily complicated.  I guess you have a programming background, but it really isn't nicely presented.  Because there are many people who make a script and never come back, it would be nice if you keep it nice and simple so that we can take a look at the code later and help people when they have problems.

I hope this helps, and if you have further questions about the scripting engine then don't be afraid to ask.


RE: Global Window-handler possible? by RdeWilde on 06-03-2008 at 11:23 AM

Sorry I haven't been clear on this, but I AM talking about PlusWindows, not the chatwindows. I'd like to have one generic code, handling my windows instead of spreading the handling allover in my code.

I don't know why you don't like my coding style, but it's just a little of OOP with Object-prototyping, nothing wrong with that. A lot better than most of the plugin-code I've seen so far. You may provide me some better example?

But it's not about that, I'd like to focus on the issue of the global window handler. I'd generally just try to catch ALL CTRL_CLICKED in events in ONE function, but I can't get them there without explicitely including every Event-function with the seperate WindowId in it. That's not what I want, because the windows should be flexible.


RE: Global Window-handler possible? by markee on 06-03-2008 at 12:42 PM

Ok, sorry it has been a couple of weeks since I have done some scripting so I didn't read it all that well.

Unfortunately you can't create the one function to the best of my knowledge except by using notifications from the win32 API.  The biggest issue with this is that you will probably need to use a 3 dimensional array so that you have the handle for each window and then each element within the window (which then obviously can use a lot of memmory in large cases and would either require reading the XML for the window or hard coding each element for each window).

Personally I think this will take more code and will be less effective.  The whole idea of using multiple functions is because each window has different features and hence different requirements.

What you might want to do instead is something like the following:

code:
function OnWindowEvent_CtrlClicked(PlusWnd,CntrlId){
switch(CntrlId){
case "first": callCommonFunction(PlusWnd.Handle);
case "second" : callAnotherFunction();
}
}

function OnYetAnotherWindowEvent_CtrlClicked(PlusWnd,CntrlId){
switch(CntrlId){
case "first": callCommonFunction(PlusWnd.Handle);
case "third" : callYetAnotherFunctionWhichInstAbove();
}
}

function callCommonFunction(oHandle){
Interop.Call("User32.dll", "MessageBoxW", oHandle, "Hello!", "Example Message", 0); // Either window will have this message displayed on top
}

I know this isn't exactly what you are looking for, but it is probably the best solution I can think of off of the top of my head.


Also, I can understand the OOP, but it is more complex than you need to make it.  The likes of iTunes+ and NowPlaying are two scripts that use objects effectively and are much easier to read imho (it might just be those underscores that are doing it to me and the lack of spaces due to the forum).  This is purely my own opinion though, I'm not saying you have to code the way I like, I was just making a recommendation.  I don't think there is any reason why you should need to make things complex in such a nice and basic language :tongue:
RE: Global Window-handler possible? by RdeWilde on 06-03-2008 at 02:28 PM

Thanks for clearing up some things. I understand where you're going, but that's exactly what I'm trying to prevent. The multidimensional array you name it, is an object in my code. It won't take more memmory, it's even more compact than writing out each seperate window.

If you take a close look at my code, you'll notive my constructor takes the argument of windows and elements, combined with a function to execute:

code:
new cWindow(
  {'__OS_wndCalender':
    {'__OS_btnStatusSave' : function()
       {
          MsgPlus.DisplayToast('Made IT!');
       }
    }
  }
);

Here you have the structure of all elements (defined just one here, but could be a lot more) inside of all windows, which are filled with the function to execute. It could also include a reference to execute another part of the script, which makes the code flexible.

Another advantage of this object-collection is that I could easily make a function to manage the elements and windows. I have the openWindow function, which will make every new window available to this control. Thereby I could add a function to each window like 'addElementControl', which'll give me the feature to dynamically add (handling of) control-elements.

In the code you're showing as an alternative, there's no such possibility. I'll have to hardcore every change and every action in seperate functies. I think it's LESS readable and workable instead of a nice collection, but that's indeed just a personal opinion.

I'll keep thinking about the handling. I've been trying to dynamically create the functions to handle the windows and reference them to the global one, but i don't think that'll be a nice workaround....