Skip to content

Instantly share code, notes, and snippets.

@MarkTiedemann
Created February 6, 2025 23:47
Show Gist options
  • Save MarkTiedemann/31351c30a9d2eec58d5419852bbb35e9 to your computer and use it in GitHub Desktop.
Save MarkTiedemann/31351c30a9d2eec58d5419852bbb35e9 to your computer and use it in GitHub Desktop.
import {
SM_CXSCREEN,
SM_CYSCREEN,
GetSystemMetrics,
SPI_GETWORKAREA,
SystemParametersInfoA,
} from "https://win32.deno.dev/0.4.1/UI.WindowsAndMessaging";
import {
allocRECT,
RECTView,
} from "https://win32.deno.dev/0.4.1/Graphics.Dwm";
export function screen() {
return {
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsystemmetrics
width: GetSystemMetrics(SM_CXSCREEN),
height: GetSystemMetrics(SM_CYSCREEN),
};
}
export function workArea(): { top: number, bottom: number, left: number, right: number } {
// https://learn.microsoft.com/en-us/windows/win32/api/windef/ns-windef-rect
const rect = allocRECT();
const rectView = new RECTView(rect);
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfoa
const success = SystemParametersInfoA(SPI_GETWORKAREA, 0, rect, 0);
if (!success) {
throw new Error(`Failed to query work area`);
}
return {
top: rectView.top,
bottom: rectView.bottom,
left: rectView.left,
right: rectView.right,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment