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

Help with API
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Help with API
In theory, you can use any functions provided in the Win32 API. However, there are some disadvantages Plus! Live has because its scripting engine isn't yet perfect. For example, you can't register a notification for a control since there's no Control object which could have a RegisterMessageNotification function, such function only exists for the PlusWnd object. Except from that, any function should work (unless I forgot something?).

Some examples:
  • ShellExecute - Used to start a program. In this example the program "MyProg.exe" in the script folder with the parameter /JustDoIt, which should get recognized by the program.
    code:
    var Result = Interop.Call(
       /* Library to call */ "shell32",
       /* Function to call */ "ShellExecuteW",
       /* hWnd */ 0,
       /* lpOperation */, "open",
       /* lpFile */, MsgPlus.ScriptFilesPath + "\\MyProg.exe",
       /* lpParameters */ "/JustDoIt",
       /* lpDirectory */ 0,
       /* nShowCmd */, 0
    );
    if(Result <= 32) //If Result is less than or equal to 32, an error has been returned.
       Debug.Trace("ShellExecute returned an error! Result: "+Result);
    else
       Debug.Trace("ShellExecute succeeded");
  • SendMessage - Used to send a window message to a window or window control. In this example, the window caption will be changed by the WM_SETTEXT message.
    code:
    //Window
    var PlusWnd = MsgPlus.CreateWnd("Windows.xml", "WndTest");
    //String for title
    var sTitle = "My New Window";
    //DataBloc for title
    var lpTitle = Interop.Allocate((sTitle.length+1)*2);
    lpTitle.WriteString(sTitle, 0);
    //Call SendMessage with WM_SETTEXT
    var Result = Interop.Call(
       /* Library to call */ "user32",
       /* Function to call */ "SendMessageW",
       /* hWnd */ PlusWnd.Handle,
       /* WM_SETTEXT */ 0xC,
       /* wParam */ 0,
       /* lParam */ lpTitle.DataPtr
    );
    if(Result != 1) Debug.Trace("SendMessage returned an error! Result: "+Result);
  • PlusWnd.RegisterMessageNotification - Used to register a notification to a window and react on it. In this example we'll dump the new size of the window to the debug window when the user is resizing it.
    code:
    //Window
    var PlusWnd = MsgPlus.CreateWnd("Windows.xml", "WndTest");
    //Register message notification
    PlusWnd.RegisterMessageNotification(/* WM_SIZE */ 0x5, true);
    ...
    function OnWndTestEvent_MessageNotification(PlusWnd, Message, wParam, lParam) {
       if(Message == /* WM_SIZE */ 0x5) {
          var Width = lParam  & 0xFFFF; //Width is stored in low-order word of lParam
          var Height = lParam >> 16; //Height is stored in high-order word of lParam
          Debug.Trace("WndTest size: "+Width+"x"+Height);
       }
       return -1; //Let the window do its stuff with this message too
    }
Oh noees! I got beaten by vikke! :(
quote:
Originally posted by vikke
Note: Always use the unicode version of Win32 APIs instead of the ANSI version. So put a W after a function to use the unicode function (only on functions whichs contains one string in its parameters, all expect GetProcAddress).
True, I wanted to mention that but I forgot.

This post was edited on 05-26-2007 at 10:21 AM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
05-26-2007 06:52 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Help with API - by pedro_cesar on 05-26-2007 at 06:13 AM
RE: Help with API - by vikke on 05-26-2007 at 06:48 AM
RE: Help with API - by Matti on 05-26-2007 at 06:52 AM
RE: RE: Help with API - by vikke on 05-26-2007 at 06:54 AM
RE: Help with API - by mickael9 on 05-26-2007 at 09:23 AM
RE: Help with API - by Matti on 05-26-2007 at 10:21 AM
RE: Help with API - by mickael9 on 05-26-2007 at 05:30 PM
RE: Help with API - by pedro_cesar on 05-27-2007 at 01:03 AM


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