Help with SendMessage() - 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: Help with SendMessage() (/showthread.php?tid=95135)
Help with SendMessage() by Coso on 07-29-2010 at 08:27 PM
First of all I'm a n00b at scripting.
And my problem is this:
The script has a menu and when i click it, it creates a window with a button.. that works fine..
and when I push the button it should send a message in the chat window I clicked the menu...
But I don't know how to deffine the ChatWnd so I always get the same error.
'ChatWnd' is undefined
error code: -2146823279
There is no event in the chat window I what to send the message.
function OnCodedWndEvent_CtrlClicked(Wnd1, ControlId)
{
if(ControlId == "BtnSnd")
{
ChatWin.SendMessage("Message");
}
Is there a way to deffine the ChatWnd without having a event like OnEvent_ChatWndReceiveMessage(ChatWnd, Name, message, msgkind) so the script could use it later?
Lets say just by clicking the menu of the script in the chat window...?
RE: Help with SendMessage() by matty on 07-30-2010 at 01:33 PM
The reason it isn't making sense is because you are not globally defining the Chat Window object. You could do this by putting var objChatWnd; at the top of your script then in your OnEvent_MenuClicked you would assign objChatWnd = pChatWnd. The problem then becomes how do you support multiple windows. Well you would do that with the following code. Let me know if this doesn't make sense.
js code: // Object container
var oChatWnds = {};
// We clicked a menu item, let us make sure it is from the chat window
function OnEvent_MenuClicked(sMenuItemId, nLocation, pChatWnd) {
if (nLocation === MENULOC_CHATWND) {
// Create the window
var tmpWindow = MsgPlus.CreateWnd('TestXmlFile.xml', 'TestWindow');
// Store the Chat Window object in a container
oChatWnds[tmpWindow.Handle] = pChatWnd;
}
}
// We pushed a button
function OnTestWindowEvent_CtrlClicked(pPlusWnd, sControlId) {
// Make sure we are allowed to send a message
// and that the contact isn't offline or blocked
if (oChatWnds[pPlusWnd.Handle].EditChangeAllowed === true)
// Send the message
oChatWnds[pPlusWnd.Handle].SendMessage('This message was sent from clicking a control in a window.');
}
// Our window is closed we need to remove
// the association in the object container
function OnTestWindowEvent_Destroyed(pPlusWnd) {
delete oChatWnds[pPlusWnd.Handle];
}
function OnEvent_ChatWndDestroyed(pChatWnd) {
for (var i in oChatWnds) {
if (oChatWnds[i].Handle === pChatWnd.Handle) {
// Close the original window
Interop.Call('user32', 'SendMessageW', i, 0x10, 0, 0);
// Delete the object from the container
delete oChatWnds[i];
}
}
}
RE: RE: Help with SendMessage() by Coso on 07-30-2010 at 02:46 PM
For me it's not working... but at least it's a different error this time
quote: Object doesn't support this property or method (code: -2146827850)
Function OnCodedWndEvent_CtrlClicked returned an error. Code: -2147352567
The error is on sendmessage line:
js code: oChatWnds[pPlusWnd.Handle].SendMessage = 'This message was sent from clicking a control in a window.';
RE: Help with SendMessage() by matty on 07-30-2010 at 02:48 PM
quote: Originally posted by Coso
For me it's not working... but at least it's a different error this time
Can you post all of your code please.
Also please use the following tags [code=js][/code].
Corrected it. Should be:
js code: oChatWnds[pPlusWnd.Handle].SendMessage('This message was sent from clicking a control in a window.');
RE: RE: Help with SendMessage() by Coso on 07-30-2010 at 03:06 PM
LoL
I didn't see that...
Thank you!
Now it works perfectly...
RE: Help with SendMessage() by matty on 07-30-2010 at 04:09 PM
Glad it works. If you need anything else you know where to find us.
|