What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Help]Sending a ChatWnd message

[Help]Sending a ChatWnd message
Author: Message:
PedroGabriel
Junior Member
**


Posts: 22
– / – / Flag
Joined: Jun 2010
O.P. Huh?  [Help]Sending a ChatWnd message
Hello,
can somebody tell me if theres some way to send a message without using the OnEvent_ChatWndReceiveMessage

Me and my friend was trying to know how for some time but thats hard...

ChatWnd.SendMessage(str);
only works if you know the ChatWnd,but how to send from an event like:
function OnEvent_Timer(Timer)

We can send a message from another function or only from the
OnEvent_ChatWndReceiveMessage
?

thanks for attention

This post was edited on 07-31-2011 at 08:58 PM by PedroGabriel.
07-31-2011 08:33 PM
Profile E-Mail PM Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
35 / Male / Flag
Joined: Aug 2006
RE: [Help]Sending a ChatWnd message
In a situation like that, I tend to store the ChatWnd Ogbject as a global variable from a different function so I can access it later
<Eljay> "Problems encountered: shit blew up" :zippy:
07-31-2011 09:09 PM
Profile PM Find Quote Report
PedroGabriel
Junior Member
**


Posts: 22
– / – / Flag
Joined: Jun 2010
O.P. RE: [Help]Sending a ChatWnd message
I already have tried to do look:

Javascript code:
var window = null
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MsgKind){
    window = ChatWnd;
    Debug.Trace(window);
}


return:

Function: OnEvent_ChatWndReceiveMessage
Error: Type mismatch (code: -2146828275)
An error occurred in function OnEvent_ChatWndReceiveMessage.
Code: -2147352567

Can somebody give me a tip?
07-31-2011 09:18 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: [Help]Sending a ChatWnd message
Debug.Trace needs a string as parameter but you're passing in a ChatWnd object. This cannot be implicitly converted to a string and thus JScript throws a type mismatch error.

When debugging, I usually output the handle of a window to check if the variable contains a window:
Javascript code:
Debug.Trace(window.Handle)

You might actually want to use this handle to make a more versatile window storage. Also, by using a OnEvent_ChatWndSendMessage you can properly distinguish sent messages from received messages using a similar storage.
Javascript code:
// Create containers to
var ChatWnds = {}, ChatWndIsReceivedMessage = {};
 
// Store the chat window object in our container when it is opened
function OnEvent_ChatWndCreated(ChatWnd) {
    ChatWnds[ChatWnd.Handle] = ChatWnd;
    ChatWndIsReceivedMessage[ChatWnd.Handle] = true;
}
 
// Remove the object from the containers if the window is closed
function OnEvent_ChatWndDestroyed(ChatWnd) {
    delete ChatWnds[ChatWnd.Handle];
    delete ChatWndIsReceivedMessage[ChatWnd.Handle];
}
 
// If we send a message, mark it in the container
function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
    ChatWndIsReceivedMessage[ChatWnd.Handle] = false;
}
 
// Create a timer when a message is received
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind) {
    if (ChatWndIsReceivedMessage[ChatWnd.Handle]) {
        // If this block is reached, the message has to be
        // a message received from a contact
 
        // Set a timer and concatenate the handle in the timer ID
        MsgPlus.AddTimer("DoSomethingAwesome:" + ChatWnd.Handle, 100);
    }
    // Mark as received in the container
    ChatWndIsReceivedMessage[ChatWnd.Handle] = true;
}
 
// Handle the timers
function OnEvent_Timer(TimerId) {
    if (TimerId.indexOf("DoSomethingAwesome:") === 0) {
        // Get the ChatWnd handle out of the TimerId
        var ChatWndHandle = TimerId.substr("DoSomethingAwesome:".length);
        // Get the ChatWnd object associated with this handle
        var ChatWnd = ChatWnds[ChatWndHandle];
        // Do something awesome here
    }
}

Derived from matty's reply to Reply to any message.

One thing to note: you should generate the containers at OnEvent_Initialize to account for the case where the script is started while the current is already signed in (e.g. when it's just installed or activated). Simply enumerate Messenger.CurrentChats and add them to the objects.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
07-31-2011 10:07 PM
Profile E-Mail PM Web Find Quote Report
« 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