Created
February 6, 2025 23:47
-
-
Save MarkTiedemann/31351c30a9d2eec58d5419852bbb35e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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