I highly recommend you to take a look at other scripts when you're learning to use the Win32 API functions. Mainly, it's about understanding what parameters require what type of variables (lpsz = string buffer pointer, long = integer,...) and converting it to a Plus! script.
So, here's what I'd like to say to you:
- The SystemParametersInfo function is implemented as both Unicode and ANSI version in the API, as noted in the Requirements section at the bottom of that MSDN page. That means, that we should use the "SystemParametersInfoW" function because JScript uses Unicode.
- When the documentation says that the pvParam must be a RECT structure for SPI_GETWORKAREA, you should create one! It won't know that you have 2 variables to retrieve the information, and it doesn't expect that anyway! You should therefore create a DataBloc which can hold 4 values (left, top, right, bottom) of 4 bytes each (as they're LONG types), thus 16 bytes in total for your DataBloc. Then, you can pass that DataBloc to the API function.
- It's recommended that you check the return value of the function. When it's zero, an error has occured and thus your script shouldn't continue with the retrieving.
- The RECT structure will be filled with all the data you need then. Since the right and bottom edges are exclusive, you can simply substract right from left to get the width and bottom from top to get the height. After you safely stored this information in 2 variables, you can clear the RECT to save some memory. Imagine having all programs forgetting to clean their used memory, now that would cause some memory overflows!
code:
var SPI_GETWORKAREA = 48;
//Create a RECT structure to receive the work area rectangle in
var RECT = Interop.Allocate(16);
//Call the API function
var Result = Interop.Call("user32", "SystemParametersInfoW", SPI_GETWORKAREA, 0, RECT, 0);
//Check the result
if(Result == 0) {
Debug.Trace("SystemParametersInfo failed!");
//Do your error handling stuff here...
}
//Read the data from the structure
var ScreenWidth = RECT.ReadDWORD(8) - RECT.ReadDWORD(0);
var ScreenHeight = RECT.ReadDWORD(12) - RECT.ReadDWORD(4);
//Clear the structure, because we no longer need it
RECT.Size = 0;
//Do whatever you want with the ScreenWidth and ScreenHeight variables...