CookieRevised
Elite Member
Posts: 15517 Reputation: 173
– / /
Joined: Jul 2003
Status: Away
|
RE: How to - Clicking toast to bring up contact list?
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.
This post was edited on 06-25-2007 at 02:41 AM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
|
|