What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Question] Call SystemParametersInfo

[Question] Call SystemParametersInfo
Author: Message:
mynetx
Skinning Contest Winner
*****

Avatar
Microsoft insider

Posts: 1175
Reputation: 33
37 / Male / Flag
Joined: Jul 2007
O.P. [Question] Call SystemParametersInfo
My next problem is one regarding the SystemParametersInfo Function (Windows).

I got the code
code:
var SPI_GETWORKAREA = 48;
var intScreenX, intScreenY;
// some code not found out yet
Interop.Call("user32", "SystemParametersInfo", SPI_GETWORKAREA, 0, outRect, 0);
// some code not found out yet
Debug.Trace(intScreenX + ", " + intScreenY);

Should return the desktop size minus taskbar etc. (in difference to Interop.Call('user32','GetSystemMetrics',0x4e);).
Anybody wants to help me out in this regard as how to solve it?
mynetx - Microsoft, enhanced.

You have a problem or issue with Windows, Internet
Explorer or Office?
Send a tweet!
01-17-2008 04:58 PM
Profile E-Mail PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: [Question] Call SystemParametersInfo
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! :O
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...
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
01-17-2008 05:24 PM
Profile E-Mail PM Web Find Quote Report
mynetx
Skinning Contest Winner
*****

Avatar
Microsoft insider

Posts: 1175
Reputation: 33
37 / Male / Flag
Joined: Jul 2007
O.P. RE: [Question] Call SystemParametersInfo
Thank you Mattike for your tutorial (Y).
01-17-2008 05:33 PM
Profile E-Mail PM Web Find Quote Report
« 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