Hey, James...
Unfortunately, Editor doesn't seem to offer any direct methods of
getting the screen resolution. So, here's just enough black magic to
get the information from the Windows API via ACL.
####################
# Get dimensions of monitor containing the window with the given ID.
# Get just the working area (minus taskbar) by passing
# a non-zero value for the optional "workarea" argument.
# Returns a string of the form "WxH+X+Y" (window geometry)
# or a message starting with "Error " on failure.
function getScreenSize(window, workarea=0)
{
# Get a handle to the Windows User32 library
local dll = dl_load("user32");
if (!dll) { return "Error loading library"; }
# Get a handle to the MonitorFromWindow function
local MonitorFromWindow = dl_find(dll, "MonitorFromWindow");
if (!MonitorFromWindow)
{
dl_unload(dll);
return "Error getting monitor lookup function";
}
# Get a handle to the GetMonitorInfo function
local GetMonitorInfo = dl_find(dll, "GetMonitorInfoW");
if (!GetMonitorInfo)
{
dl_unload(dll);
return "Error getting monitor info function";
}
# Get a handle to the monitor that the window is on
local hwnd = window_xid(window);
# 0, 1, 2 = MONITOR_DEFAULTTO{NULL,PRIMARY,NEAREST}
local monitor = dl_call(MonitorFromWindow, hwnd, 2);
# Get the geometry of the monitor
local rect[];
# struct RECT { long left; long top; long right; long bottom; }
# struct MONITORINFO { DWORD cbSize; RECT rcMonitor;
# RECT rcWork; DWORD dwFlags; }
local geom = pack("ll4l4l", 40, 0, 0, 0, 0, 0, 0, 0, 0, 0);
local ret = dl_call(GetMonitorInfo, monitor, geom);
if (ret == 0)
{
dl_unload(dll);
return "Error getting monitor info";
}
# Unpack just the RECT we're interested in, skipping the rest
ret = "x" . (workarea != 0 ? 20 : 4) . "l4";
unpack(ret, geom, rect);
geom = " . (rect[3] - rect[1]) . "x" . (rect[4] - rect[2]);
geom = geom . "+" . rect[1] . "+" . rect[2];
dl_unload(dll);
return geom;
}
####################
Use with caution. 😉
-Brandon 🙂
Brandon Ibach
Developer, Single-Sourcing Solutions, Inc.