What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Tips

Pages: (2): « First [ 1 ] 2 » Last »
Tips
Author: Message:
surfichris
Former Admin
*****

Avatar

Posts: 2365
Reputation: 81
Joined: Mar 2002
O.P. Tips
A collection of tips relating to scripting.

ActiveX Objects
You can access ActiveX objects just like you can using IE.

var ob = new ActiveXObject("name here");
if(ob == false)
{
    Debug.trace("ActiveX objection creation failed");
}

Starting a program:
var shell = new ActiveXObject("wscript.shell");
shell.Run("notepad.exe");

(Will start notepad.exe)

Changing a message being sent:
You can return a message from the ChatWndSendMessage function and it will change the message before it is sent. If you don't return a message, the intercepted message will be sent.

The following code will replace all instances of hi with test.

function OnEvent_ChatWndSendMessage(ChatWnd, sMessage)
{
   return sMessage.replace("hi", "test");
}

03-13-2006 12:06 PM
Profile PM Find Quote Report
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
36 / Male / Flag
Joined: Mar 2004
RE: Tips
To use send data to websites you use XMLHttpRequest

code:
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET", "http://shoutbox.menthix.net", true);

    xmlhttp.onreadystatechange=function() {
          if (xmlhttp.readyState==4) {
              Debug.Trace(xmlhttp.responseText);
          }
         }
xmlhttp.send('');




:P that will print msghelp.net's html to your debug console

edit:
changed the async flag to true on the xmlhttprequest object (so it doesnt freeze the chats while doing its stuff)

This post was edited on 03-14-2006 at 01:09 AM by -dt-.
[Image: dt2.0v2.png]      Happy Birthday, WDZ
03-13-2006 12:11 PM
Profile PM Web Find Quote Report
segosa
Community's Choice
*****


Posts: 1407
Reputation: 92
Joined: Feb 2003
RE: Tips
Gah, finally figured out how to use what's in the IDL file.

First I was messing around with ActiveXObject() trying to create an instance, but it's much simpler.

For example,

code:
    //IMPMsgPlus interface
    [
        uuid(45C2DA37-53C8-4497-9C87-9E6A6DFF2B7C),
        helpstring("MPScript Messenger Plus! Interface")
    ]
    interface _IMPMsgPlus : IUnknown
    {
..snip..
        HRESULT DisplayToast([in] BSTR sTitle, [in] BSTR sMessage, [in,optional] VARIANT sCallback, [in,optional] VARIANT vCallbackParam, [out,retval] VARIANT_BOOL *bDisplayed);
        HRESULT DisplayToastContact([in] BSTR sTitle, [in] BSTR sContactName, [in] BSTR sMessage, [in,optional] VARIANT sCallback, [in,optional] VARIANT vCallbackParam, [out,retval] VARIANT_BOOL *bDisplayed);
    }


You take the name, which in this case is IMPMsgPlus and remove the IMP, making it MsgPlus. Then to, say, call DisplayToast you would simply use MsgPlus.DisplayToast()
The previous sentence is false. The following sentence is true.
03-13-2006 12:39 PM
Profile PM Find Quote Report
surfichris
Former Admin
*****

Avatar

Posts: 2365
Reputation: 81
Joined: Mar 2002
O.P. RE: Tips
Reading the contents of a file:
(This code contains no error handling - you're expected to add it yourself)

- See note below on file paths.

code:
function get_file_contents(file)
{
    var fileSys = new ActiveXObject("Scripting.FileSystemObject");
    var fileH = fileSys.OpenTextFile(file, 1, 0);
    var text = fileH.ReadAll();
    fileH.close();
    return text;
}

Checking if a file exists:

- See note below on file paths.

code:
function file_exists(file)
{
    var fileSys = new ActiveXObject("Scripting.FileSystemObject");
    if(fileSys.FileExists(file))
    {
        return true;
    }
    else
    {
        return false;
    }
}

Note:
You need double slashes in the path - ex, C:\\test\\file.txt.

Also - when reading files, the base path is actually your windows profile directory (C:\Documents and Settings\....). If you need to read something from your scripts directory, then you would use:

myFile = MsgPlus.ScriptFilesPath+"\\file.txt";

This post was edited on 03-13-2006 at 01:34 PM by surfichris.
03-13-2006 01:13 PM
Profile PM Find Quote Report
Volv
Skinning Contest Winner
*****

Avatar

Posts: 1233
Reputation: 31
35 / Male / Flag
Joined: Oct 2004
RE: Tips
Just a simple module for perhaps making Plus Menus easier to create.

Download Module: util_MsgPlus.js


Example Usage:

Generating the Menu
code:
function OnGetScriptMenu(){
    //Create new menu
    var myMenu = new PlusMenu;
   
    //Populate menu
        //Add a menu item
        myMenu.addItem("mnuItem1", "Item #1");
        myMenu.addItem("mnuItem2", "Item #2", false); //Disabled menu item
       
        //Add a separator because separators are pretty cool...
        myMenu.addSeparator();
       
        //Create a sub menu
        myMenu.openSubMenu("My 1st Sub Menu!");
            //Add a menu item to the sub menu
            myMenu.addItem("mnuItem3", "Item #3");
        myMenu.closeSubMenu();
       
        //Create a disabled sub menu
        myMenu.openSubMenu("My 2nd Sub Menu!", false);
        myMenu.closeSubMenu();
   
    //Build menu
    return myMenu.build();
}

Detecting when a menu item is clicked
code:
function OnEvent_MenuClicked(sMenuId){
    if(sMenuId=="mnuItem1"){
        MsgPlus.DisplayToast("Menu Click", "Menu Item #1 was clicked!");
    }
}


This post was edited on 04-19-2006 at 07:15 AM by Volv.
04-19-2006 06:29 AM
Profile PM Find Quote Report
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
36 / Male / Flag
Joined: Mar 2004
RE: Tips
Showing those crazy MS agent characters


First the user must have a MS agent installed for this example we will use Merlin
Download him here...
http://download.microsoft.com/download/1/d/b/1dbe...f3c4669/Merlin.exe

for more agents see here http://www.msagentring.org/chars.htm


Code to load your character
code:
//open a new object of the agent control
var Agents = new ActiveXObject("agent.control.2");
Agents.Connected = true;

//now to load our character into that control.
Agents.Characters.Load("Merlin","C:\\WINDOWS\\msagent\\chars\\Merlin.acs");
var merlin = Agents.Characters.Character("Merlin");




To show him you do
code:
merlin.Show();


To hide him you do
code:
merlin.Hide();



To make him speak you do (must be showing to speak this)
code:
merlin.Speak('dt is your master now');


To make him think
code:
merlin.Think("Oh wow im thinking :P");


each character also has gestures which they can do like...
to make merlin lift his arms and then point to the right..
code:
merlin.Play("GestureUp");
merlin.Play("GestureRight");



To move a character you do
code:
merlin.MoveTo(300,200);

which makes merlin to a crazy flying animation to that point



This code shows merlin  makes him fly to a point  then say hello , raise his hands and then hide.
code:
//open a new object of the agent control
var Agents = new ActiveXObject("agent.control.2");
Agents.Connected = true;

//now to load our character into that control.
Agents.Characters.Load("Merlin","C:\\WINDOWS\\msagent\\chars\\Merlin.acs");
var merlin = Agents.Characters.Character("Merlin");

merlin.Show();
merlin.MoveTo(300,200);
merlin.Speak('Hello');
merlin.Play("GestureUp");
merlin.Hide();




To make your agent speak what hes saying outloud you need to install the MS speech stuff
http://activex.microsoft.com/activex/controls/agent2/tv_enua.exe
http://activex.microsoft.com/activex/controls/sapi/spchapi.exe
[Image: dt2.0v2.png]      Happy Birthday, WDZ
04-19-2006 06:57 AM
Profile PM Web Find Quote Report
davidt
New Member
*


Posts: 7
Joined: Aug 2006
RE: Tips
If you are calling an XML service and expecting a reply in XML form parse it with MSXML...

code:
// -------------------------------------------------------------------
// XML request
function NewRequest(service)
{
    xmlFile = service;
    Debug.Trace("Calling: "+xmlFile);
    var xml = new ActiveXObject("MSXML2.DOMDocument.4.0");
    xml.validateOnParse = false;
    xml.async = false;
    xml.load(xmlFile);
    var resp = xml.documentElement;
   
    return resp;
}

The object returned represents the root tag in the document. To get its first child tag

code:
var root = NewRequest("http://...");
var child = root.childNodes.item(0);
Debug.Trace("First child's text: " + child.text);

For more information on DOMDocument object... http://msdn.microsoft.com/library/default.asp?url...lrfdomdocument.asp

hope it helps
08-15-2006 09:21 AM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15517
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: RE: Tips
To show how things can be made shorter:


As an example I'll take the 'file existing' routine shown by Chris Boulton.
code:
// Checking if a file exists:

function file_exists(file)
{
    var fileSys = new ActiveXObject("Scripting.FileSystemObject");
    if(fileSys.FileExists(file))
    {
        return true;
    }
    else
    {
        return false;
    }
}
If you use an IF THEN ELSE structure to check on a function which only returns true or false on its own, you can do:
code:
return fileSys.FileExists(file)
Since filesys is an object which you have defined before and since this is only used once, you don't specifically need it to be defined as a variable but you can use it directly:
code:
return new ActiveXObject("Scripting.FileSystemObject").FileExists(file)
All this makes that the function is reduced to only 1 line:
code:
function file_exists(file)
{
    return new ActiveXObject("Scripting.FileSystemObject").FileExists(file);
}


-------------------------------

Various short functions derived from VB6:

see "CookieRevised's reply to [I help them] VB2JS"
.-= A 'frrrrrrrituurrr' for Wacky =-.
10-21-2006 01:44 AM
Profile PM Find Quote Report
Plan-1130
Full Member
***

I keep askin' myself: why?

Posts: 142
73 / Male / –
Joined: Feb 2005
RE: Tips
Accessing the registry, without getting errors (see attachment):

Both variable and path should not begin with a slash (/).

ExistsRegistry (
[optional string] sub directory in the script's registry key,
[optional string] variable  in the script's registry key
)
Returns true if exists, false if not exists

DeleteRegistry (
[optional string] sub directory in the script's registry key,
[optional string] variable to remove, if not set, the whole directory will be removed
)
Deletes a variable or key.

ReadRegistry (
[optional string] sub directory in the script's registry key,
[optional string] variable to read from,
[optional string] default value in case the variable is not set yet
)
Reads the value of a key or variable, returns the value if found, returns default value if set, returns null if failed.

WriteRegistry (
[optional string] sub directory in the script's registry key,
[optional string] variable to read from,
[string] value to write,
[boolean] whether or not to overwrite if set already
)
Writes a value to a key or variable, returns the written value if overwrite is true or value did not exist, returns original value if overwrite is false and value did exist, returns null if failed.


Examples:
code:
ExistsRegistry("example", "MyAge");
// returns false

ReadRegistry("example", "MyAge");
// returns null

WriteRegistry("example", "MyAge", 16);
// writes 16, returns 16

ExistsRegistry("example", "MyAge");
// returns true

WriteRegistry("example", "MyAge", 17, false);
// does not write, returns 16

DeleteRegistry("example", "MyAge");
// deletes value

ReadRegistry("example", "MyAge", 17);
// writes 17, returns 17

WriteRegistry("example", "MyAge", 18);
// writes 18, returns 18

DeleteRegistry("example");
// deletes whole example key

both
code:
WriteRegistry("example", "MyAge", 16, false);
and
code:
ReadRegistry("example", "MyAge", 16);
will write and return 16 if value does not exist, and won't write but will return the original value if it does exist.

.txt File Attachment: Registry Access.txt (6.27 KB)
This file has been downloaded 955 time(s).

This post was edited on 10-25-2006 at 08:22 PM by Plan-1130.
My Scripts: UltimatFlooder, Advanced PSM Chat, PlusPrivacy, PlusRemote

[Image: Plan-1130.png]
10-25-2006 08:15 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Tips
quote:
Originally posted by Plan-1130
Accessing the registry, without getting errors (see attachment):

Both variable and path should not begin with a slash (/).

ExistsRegistry (
[optional string] sub directory in the script's registry key,
[optional string] variable  in the script's registry key
)
Returns true if exists, false if not exists

DeleteRegistry (
[optional string] sub directory in the script's registry key,
[optional string] variable to remove, if not set, the whole directory will be removed
)
Deletes a variable or key.

ReadRegistry (
[optional string] sub directory in the script's registry key,
[optional string] variable to read from,
[optional string] default value in case the variable is not set yet
)
Reads the value of a key or variable, returns the value if found, returns default value if set, returns null if failed.

WriteRegistry (
[optional string] sub directory in the script's registry key,
[optional string] variable to read from,
[string] value to write,
[boolean] whether or not to overwrite if set already
)
Writes a value to a key or variable, returns the written value if overwrite is true or value did not exist, returns original value if overwrite is false and value did exist, returns null if failed.


Examples:
code:
ExistsRegistry("example", "MyAge");
// returns false

ReadRegistry("example", "MyAge");
// returns null

WriteRegistry("example", "MyAge", 16);
// writes 16, returns 16

ExistsRegistry("example", "MyAge");
// returns true

WriteRegistry("example", "MyAge", 17, false);
// does not write, returns 16

DeleteRegistry("example", "MyAge");
// deletes value

ReadRegistry("example", "MyAge", 17);
// writes 17, returns 17

WriteRegistry("example", "MyAge", 18);
// writes 18, returns 18

DeleteRegistry("example");
// deletes whole example key


I posted a registry module already that uses the Windows API http://shoutbox.menthix.net/attachment.php?pid=738349
10-25-2006 08:21 PM
Profile E-Mail PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« 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