Shoutbox

How to - Clicking toast to bring up contact list? - 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: How to - Clicking toast to bring up contact list? (/showthread.php?tid=75601)

How to - Clicking toast to bring up contact list? by stu on 06-24-2007 at 09:51 PM

For a script that I have been working on, I have it display a toast. How do I set it up so that when you click on this toast, it will open the contact list?


RE: How to - Clicking toast to bring up contact list? by deAd on 06-24-2007 at 10:55 PM

code:
// First, define a callback function for the toast click.
function OnToastClick(pParam){
    // In this function, we will show the contact list.
    // To do this, we will tell the tray icon listener window that it has been double clicked.
    // First we need a handle to the tray listener window.

    var hListener = Interop.Call('User32', 'FindWindowW', 'MSNHiddenWindowClass', 0);
    if(hListener){ // Check if the window was found.
        Interop.Call('User32', 'SendMessageW', hListener, 0xC350, 0, 0x203); // Tell the listener that it was clicked.
    }
}

// Now, all we need to do is create a toast with this callback function.
function ShowToast(){
    MsgPlus.DisplayToast('Example', 'Click here!', null, 'OnToastClick', null);
}

RE: How to - Clicking toast to bring up contact list? by stu on 06-24-2007 at 11:10 PM

Thanks :)


RE: How to - Clicking toast to bring up contact list? by CookieRevised on 06-25-2007 at 02:33 AM

The above code is not polygamy safe. This means that you will get in trouble if you have more than one Messenger client open. To make it polygamy safe/compatible:

code:
// First, define a callback function for the toast click.
function OnToastClick() {
    // In this function, we will show the contact list (POLYGAMY SAFE).
    // To do this, we will tell the tray icon listener window that it has been double clicked.
    var hWnd = 0;
    var tIDCurrent = Interop.Call('Kernel32', 'GetCurrentThreadId');
    while (hWnd = Interop.Call('User32', 'FindWindowExW', 0, hWnd, 'MSNHiddenWindowClass', 0)) {
        if (Interop.Call('User32', 'GetWindowThreadProcessId', hWnd, 0) === tIDCurrent) {
            // If the hidden window was found, tell it we double clicked the tray icon
            Interop.Call('User32', 'SendMessageW', hWnd, /* REGISTERED MSG */ 0xC350, 0, /* WM_LBUTTONDBLCLK */ 0x203);
            break;
        }
    }
    /*
        // Another method is to use the MSNMSGRBlObj class instead:
        var hWnd = 0;
        var tIDCurrent = Interop.Call('Kernel32', 'GetCurrentThreadId');
        while (hWnd = Interop.Call('User32', 'FindWindowExW', 0, hWnd, 'MSNMSGRBlObj', 0)) {
            if (Interop.Call('User32', 'GetWindowThreadProcessId', hWnd, 0) === tIDCurrent) {
                Interop.Call('User32', 'SendMessageA', hWnd, 0x42A, 0, 0);
                break;
            }
        }

    */
}

// Now, all we need to do is create a toast with this callback function.
function ShowToast() {
    MsgPlus.DisplayToast('Example', 'Click here!', null, 'OnToastClick', null);
}

If you do stuff with windows like that (eg: sending messages to specific Messenger windows etc), always keep it mind that windows are not unique and that two or more windows of the same kind (class) can exist!

So to avoid that you do stuff with the wrong window, you need to check if the window belongs to the thread you seek. And since scripts are run within the same thread as Messenger, you can simply compare the current thread (which is the one from the script) with the thread of the window. If they are the same you have found the correct window. If the thread id is different you may have found a window with the same class, but it would belong to another Messenger client in this case.

;)
RE: How to - Clicking toast to bring up contact list? by stu on 06-25-2007 at 02:51 AM

Ok, thanks Cookie, may have had issue later on down the road. I am only using this for a script I made to display a random lyric in my personal message, and it also displays a toast with the lyric, so not a huge deal, but I guess you never know.