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.