Shoutbox

Silent Messages - 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: Silent Messages (/showthread.php?tid=70704)

Silent Messages by bigbob85 on 01-15-2007 at 10:06 AM

Hey,

Im wondering if anyone would have any ideas how to send a message to a chat window silently (not really silently), so you don't loose focus from the current window.

Is it even possible?


RE: Silent Messages by Felu on 01-15-2007 at 10:48 AM

code:
ChatWnd = Messenger.OpenChat("smarterchild@hotmail.com");//Open the ChatWnd
ChatWnd.SendMessage("Testing");//Send the Message
Interop.Call("User32", "SendMessageW", ChatWnd.Handle, 274, 0xF020, null);//Minimize the ChatWnd
I guess thats what you want [Image: msn_tongue.gif].

Edit: Fixed
RE: Silent Messages by bigbob85 on 01-15-2007 at 11:11 AM

Works well... Cept..

Bad calling convention detected for "SendMessageW" in "User32". The function must be declared with __stdcall and called with the appropriate number of parameter.

In the debug window...
* bigbob85 googles


RE: Silent Messages by Plik on 01-15-2007 at 11:19 AM

Change it to

code:
Interop.Call("User32", "SendMessageW", ChatWnd.Handle, 274, 0xF020, 0);//Minimize the ChatWnd

Because SendMessage wants 4 parameters, but that last (lParam) isn't used when you minimize
RE: Silent Messages by bigbob85 on 01-16-2007 at 10:01 AM

Felu told me to change it to true,  and it works. But I'll use 0, it seems more... correct :P

But isnt there a way to get the current window handle, send message,  then bring the original to the front?

code:
var CurWindow = Interop.Allocate(32);
Interop.Call('User32', 'GetTopWindow', CurWindow);
// Send Message
Interop.Call("User32", "BringWindowToTop", CurWindow);

And

code:
//var CurWindow = Interop.Allocate(32);
var CurWindow;
Interop.Call('User32', 'GetTopWindow', CurWindow);
//Debug.Trace(CurWindow);
//Debug.Trace(CurWindow.Handle);

Contact.SendMessage("/np");
Interop.Call('User32','ShowWindow', CurWindow, SW_SHOW);

Not sure if I'm ment to read this differently, or define CurWindow differently...

SW_SHOW is definded aswell. (its 5)


code:
var CurWindow = Interop.Allocate((255 *2) +2);
Interop.Call('User32', 'GetTopWindow', CurWindow);
ChatWnd.SendMessage("/np");
Interop.Call('User32','ShowWindow', CurWindow.ReadString(0), SW_SHOW);
Shouldnt this one work?
RE: Silent Messages by Felu on 01-16-2007 at 02:09 PM

code:
TopWnd = Interop.Call('User32', 'GetForegroundWindow');//Get the Active Window
ChatWnd = Messenger.OpenChat("smarterchild@hotmail.com");//Open the ChatWnd
ChatWnd.SendMessage("Testing");//Send the Message
Interop.Call("User32", "SendMessageW", ChatWnd.Handle, 274, 0xF020, null);//Minimize the ChatWnd
Interop.Call("User32", "BringWindowToTop", TopWnd);//Get the Active Window _BEFORE_ Sending the message on top


RE: Silent Messages by MrT on 01-17-2007 at 04:26 PM

code:

function sendmsg(kime,msj) {

for(var e = new Enumerator(Messenger.CurrentChats); !e.atEnd(); e.moveNext())
      {
        var curWnd = e.item();
        for(var f = new Enumerator(curWnd.Contacts); !f.atEnd(); f.moveNext())
        {
         
         
         if(f.item().Email == kime)
          {
            varmi = 1;
            ChatWnd = curWnd;
            break;
          }
         
         
          else {
         
         
          if(varmi == null) {
            varmi = 0;
          }

         
          }
         
         
          }
}
         if(varmi == 1) {
         ChatWnd.SendMessage(msj);
         }
         if(varmi == 0) {
         kisi = Messenger.OpenChat(kime);
         kisi.SendMessage(msj);
         }
}



if (you have a chat window with your contact)
   { send message }
else
   { open chat window
      send message }

:D

->    sendmsg("smarterchild@hotmail.com","hi")
RE: Silent Messages by Eljay on 01-17-2007 at 04:29 PM

quote:
Originally posted by MrT
...
if (you have a chat window with your contact)
   { send message }
else
   { open chat window
      send message }

:D

->    sendmsg("smarterchild@hotmail.com","hi")

That is what OpenChat already does though...
quote:
Originally posted by Scripting Documentation
The Messenger:: OpenChat function opens a chat window with the specified contact. If a chat window with this contact is already opened, the window is activated.

RE: RE: Silent Messages by markee on 01-18-2007 at 12:26 AM

quote:
Originally posted by Eljay
quote:
Originally posted by MrT
...
if (you have a chat window with your contact)
   { send message }
else
   { open chat window
      send message }

:D

->    sendmsg("smarterchild@hotmail.com","hi")

That is what OpenChat already does though...
quote:
Originally posted by Scripting Documentation
The Messenger:: OpenChat function opens a chat window with the specified contact. If a chat window with this contact is already opened, the window is activated.

The window does become activated but there is a problem that the chat window object isn't returned and hence why MrT's code is needed unfortunately.
RE: RE: RE: Silent Messages by CookieRevised on 01-18-2007 at 03:53 AM

quote:
Originally posted by markee
The window does become activated but there is a problem that the chat window object isn't returned and hence why MrT's code is needed unfortunately.
?

The chat window object is returned though, MrT's code is not needed.
ChatWnd = Messenger.OpenChat("smarterchild@hotmail.com");

quote:
Syntax:
[object] OpenChat(
    [var] Contact
);

Return Value:
A ChatWnd object if the function succeeds or null if it fails.

However:
quote:
Originally posted by Felu
quote:
Originally posted by bigbob85
But isnt there a way to get the current window handle, send message,  then bring the original to the front?

code:
TopWnd = Interop.Call('User32', 'GetForegroundWindow');//Get the Active Window
ChatWnd = Messenger.OpenChat("smarterchild@hotmail.com");//Open the ChatWnd
ChatWnd.SendMessage("Testing");//Send the Message
Interop.Call("User32", "SendMessageW", ChatWnd.Handle, 274, 0xF020, null);//Minimize the ChatWnd
Interop.Call("User32", "BringWindowToTop", TopWnd);//Get the Active Window _BEFORE_ Sending the message on top



When you minimize the chat window again, the window that was on top before will already become the activated/top window again.

So this is not needed either:
    TopWnd = Interop.Call('User32', 'GetForegroundWindow');
and
    Interop.Call("User32", "BringWindowToTop", TopWnd);

This is all you need:
code:
var ChatWnd = Messenger.OpenChat("smarterchild@hotmail.com");//Open the ChatWnd
ChatWnd.SendMessage("Testing");//Send the Message
Interop.Call("User32", "SendMessageW", ChatWnd.Handle, 274, 0xF020, null);//Minimize the ChatWnd
provided the email is valid and a message can be send, so better add if (ChatWnd.EditChangeAllowed) {} too...
RE: Silent Messages by bigbob85 on 01-19-2007 at 12:31 AM

All this talk about ChatWnd is making my head spin, but I think I got a good idea.

I dont think its SendMessage that draws the windows focus, its the OpenChat. So if I dont do that, and just use the ChatWnd Iterator and then see if the contact I want to send it to is in the chat (and there is only 1 person in the chat) to then send the message. Thus, avoiding the OpenChat.

I'll try it and see if it works.

EDIT:

code:
Debug.Trace("Currently opened chat windows:");
var Windows = Messenger.CurrentChats;
var e = new Enumerator(Windows);
for(; !e.atEnd(); e.moveNext()){
    var ChatWindow = e.item();
    if (ChatWindow.Contacts.Count == 1){
        var f = new Enumerator(ChatWindow.Contacts);
        for(; !f.atEnd(); f.moveNext()){
            var Contact = f.item();
            Debug.Trace(" " + Contact.Email);
        }
    }
}

That what I made, it works to :D. Might also be able to be used in my IRC Style Chats script aswell.

Thanks for your help everyone.

EDIT 2 :

Heres a BETA version of the script. Its getting there :D.
This version is mostly operational, it just dosn't have advanced settings (Like, dont send to this contact when they are busy).

Also checks if Music Now Playing is installed.

http://bigbob85.insaneparadox.com/msgplus/script.php?scr=NP%20Updater
RE: RE: Silent Messages by CookieRevised on 01-19-2007 at 02:07 PM

quote:
Originally posted by bigbob85
All this talk about ChatWnd is making my head spin, but I think I got a good idea.

I dont think its SendMessage that draws the windows focus, its the OpenChat. So if I dont do that, and just use the ChatWnd Iterator and then see if the contact I want to send it to is in the chat (and there is only 1 person in the chat) to then send the message. Thus, avoiding the OpenChat.
That will only work if there is already a chat with that contact. If there isn't a chat open with the contact, SendMessage (and your script) will fail and produce an error.

Also note that in order to SendMessage to work, the chat window must be the active window and in focus! If it is not, SendMessage will bring the chat window automatically in front too (and restore the previous window when it is done sending). This is how Plus! works.

Also, no matter what you do, do not forget to check with EditChangeAllowed if you actually can send a message to the chat window. This is mandatory! See scripting documentation MsgPlus:: SendMessage.


PS: if the initial goal from the beginning was to only send a message when there is an existing chat window, then in the future please specify such important details. Many stuff depends on what one wants to do exactly, and if one doesn't provide such details, decent help can not be given.
RE: Silent Messages by bigbob85 on 01-19-2007 at 11:12 PM

Well, the script isn't bringing it to the top (not that I can see).
I thought I did say that this is only ment to send if the contact window is open.

And as for the chat window must be on top, and active.. Not true. Download the script and give it a go. It doesn't interrupt full screen games either.

Ill add the EditChangeAllowed check. I also have to make it more clear, that at the moment, this only works for Winamp.

EDIT :
Link : http://bigbob85.insaneparadox.com/msgplus/script.php?scr=NP%20Updater


RE: Silent Messages by CookieRevised on 01-20-2007 at 03:20 AM

quote:
Originally posted by bigbob85
Well, the script isn't bringing it to the top (not that I can see).
SendMessage always does, but as said, it restores the previous window when it is done. All this, depending on your PC speed, can be in a blink of an eye...

quote:
Originally posted by bigbob85
And as for the chat window must be on top, and active.. Not true.
true true... This is how SendMessage works... SendMessage will make the window active, otherwise Plus! can't actually send the message.


PS: forum search: "Sending message without opening window.."
RE: Silent Messages by bigbob85 on 01-20-2007 at 08:44 AM

But if it were actually bringing the window to the top, it'd interrupt the full screen games wouldn't it?

I got an Intel Core2 Duo 1.8ghz, 1gb ram. I don't consider it really fast, but it still is very very quick (maby I'm not using it right :P)