Skip to content

Instantly share code, notes, and snippets.

@skymonsters-Ks
Created December 28, 2019 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skymonsters-Ks/bc4d7d1b562887bbf2ec3a84d98738b6 to your computer and use it in GitHub Desktop.
Save skymonsters-Ks/bc4d7d1b562887bbf2ec3a84d98738b6 to your computer and use it in GitHub Desktop.
(マルチ)ディスプレイの解像度などの情報表示
#include "user32.as"
#include "gdi32.as"
#ifndef SetProcessDPIAware
#uselib "user32"
#func SetProcessDPIAware "SetProcessDPIAware"
#endif
#uselib "shcore"
#func SetProcessDpiAwareness "SetProcessDpiAwareness" int
#func GetScaleFactorForMonitor "GetScaleFactorForMonitor" int, int
#const PROCESS_PER_MONITOR_DPI_AWARE 2
#const DISPLAY_DEVICE_PRIMARY_DEVICE 4
#const DISPLAY_DEVICE_ACTIVE 1
#const ENUM_CURRENT_SETTINGS -1
#const MONITOR_DEFAULTTONULL 0
#const LOGPIXELSX 88
#const LOGPIXELSY 90
#const HALFTONE 4
#const SRCCOPY $00cc0020
#const TA_LEFT 0
#const TA_RIGHT 2
#const TA_CENTER 6
if varptr(SetProcessDpiAwareness) {
SetProcessDpiAwareness PROCESS_PER_MONITOR_DPI_AWARE
} else : if varptr(SetProcessDPIAware) {
SetProcessDPIAware
}
dim dd, 106 ; DISPLAY_DEVICE
dd = 424 ; cb
dupptr dd_name, varptr(dd) + 4, 32, 2 ; DeviceName
dup dd_flag, dd(41) ; StateFlags
dim dm, 40 ; DEVMODE
dup dm_posx, dm(11) ; dmPosition.x
dup dm_posy, dm(12) ; dmPosition.y
dup dm_width, dm(27) ; dmPelsWidth
dup dm_height, dm(28) ; dmPelsHeight
dup dm_freq, dm(30) ; dmDisplayFrequency
psLeft = 0
psTop = 0
psRight = 0
psBottom = 0
n = 0
sf = 100 * GetDeviceCaps(hdc, LOGPIXELSX) / 96
repeat
if EnumDisplayDevices(0, cnt, varptr(dd), 0) == 0 : break
if (dd_flag & DISPLAY_DEVICE_ACTIVE) == 0 : continue
EnumDisplaySettings dd_name, ENUM_CURRENT_SETTINGS, varptr(dm)
if varptr(GetScaleFactorForMonitor) {
hm = MonitorFromPoint(dm_posx, dm_posy, MONITOR_DEFAULTTONULL)
if hm == 0 : continue
GetScaleFactorForMonitor hm, varptr(sf)
}
dname(n) = dd_name
flag(n) = dd_flag & DISPLAY_DEVICE_PRIMARY_DEVICE
px(n) = dm_posx
py(n) = dm_posy
sx(n) = dm_width
sy(n) = dm_height
hz(n) = dm_freq
sc(n) = sf
psLeft = min(psLeft, dm_posx)
psTop = min(psTop, dm_posy)
psRight = max(psRight, dm_posx + dm_width)
psBottom = max(psBottom, dm_posy + dm_height)
n++
loop
moniNum = n
; screen 0, 1024, 768
gsel
redraw 0
winsx = ginfo_sx
winsy = ginfo_sy
psSizeX = psRight - psLeft
psSizeY = psBottom - psTop
if (psSizeX > psSizeY * winsx / winsy) {
rate = double(winsx - 40) / psSizeX
dox = 20
doy = winsy / 2 - rate * psSizeY / 2
} else {
rate = double(winsy - 40) / psSizeY
dox = winsx / 2 - rate * psSizeX / 2
doy = 20
}
font "arial", 12
color 220, 220, 220
gmode 5, , , 30
box psLeft, psTop, psSizeX, psSizeY
repeat moniNum
if (flag(cnt)) {
color 220, 170, 170
} else {
color 150, 200, 200
}
box px(cnt), py(cnt), sx(cnt), sy(cnt)
w = x2 - x1
h = y2 - y1
buffer 1, w, h
dc = CreateDC(dname(cnt), 0, 0, 0)
SetStretchBltMode hdc, HALFTONE
StretchBlt hdc, 0, 0, w, h, dc, 0, 0, sx(cnt), sy(cnt), SRCCOPY
DeleteDC dc
gsel
pos x1, y1
gcopy 1, 0, 0, w, h
color
pos x1 + 6, y1 + 4
mes2 strf("(%d, %d)", px(cnt), py(cnt)), TA_LEFT
x = x1 + w / 2
y = y1 + h / 2
pos x, y - 12
mes2 dname(cnt), TA_CENTER
pos x, y + 4
mes2 strf("%dx%d, %dhz, %d%%", sx(cnt), sy(cnt), hz(cnt), sc(cnt)), TA_CENTER
pos x2 - 6, y2 - 20
mes2 strf("(%d, %d)", px(cnt) + sx(cnt) - 1, py(cnt) + sy(cnt) - 1), TA_RIGHT
loop
redraw 1
stop
#deffunc box int _x, int _y, int _w, int _h
x1 = dox + rate * (_x - psLeft)
y1 = doy + rate * (_y - psTop)
x2 = dox + rate * (_x + _w - psLeft)
y2 = doy + rate * (_y + _h - psTop)
boxf x1, y1, x2 - 1, y2 - 1
color ginfo_r + 20, ginfo_g + 20, ginfo_b + 20
boxf x1 + 4, y1 + 4, x2 - 5, y2 - 5
return
#defcfunc min int _a, int _b
if _a < _b : return _a : else : return _b
#defcfunc max int _a, int _b
if _a > _b : return _a : else : return _b
#deffunc mes2 str _s, int _align
s = _s
SetTextAlign hdc, _align
TextOut hdc, ginfo_cx, ginfo_cy, s, strlen(s)
return
@skymonsters-Ks
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment