Last active
February 28, 2021 05:47
-
-
Save DeviousMalcontent/0037e2f02cdb178cf4788c13e147e31d to your computer and use it in GitHub Desktop.
Simple Console app to Get System DPI for future dpiAware apps on Windows 6 (Vista) onwards, the plan is to next build a template win32 GUI app and to test the UI scaling on my 2k monitor...
This file contains hidden or 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
; ######################################################################### | |
; | |
; Program: win32-GetSystemDPI-Console | |
; Purpose: Simple Console app to Get System DPI for future dpiAware apps on Windows 6 (Vista) onwards | |
; Author: Mark Albanese | |
; Date: 28 February 2021 | |
; Version: 1.0 | |
; Release: 1 | |
; Language: x86 Assembly / Microsoft Macro Assembler | |
; Compiler: MASM32 SDK | |
; API reference: https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getdevicecaps | |
; https://docs.microsoft.com/en-us/windows/win32/hidpi/high-dpi-desktop-application-development-on-windows | |
; Compatibility: Tested on Windows 95 after installing Vcredist.exe version 6.0 from some random website (in a VM). | |
; Comments: Running on older systems shouldn't really be an issue with how I plan to implement this function i.e VerInfo.dwMajorVersion >= 6 etc. | |
; | |
; Note: This was a port of some C code found here: | |
; https://forums.codeguru.com/showthread.php?521245-GetDeviceCaps-issue-in-Windows-7-wrong-size | |
; | |
; Next, I'll build a template win32 GUI app and test how it scales on my 2k monitor. | |
; ######################################################################### | |
.386 | |
.model flat, stdcall | |
option casemap :none ; case sensitive | |
; ######################################################################### | |
include masm32rt.inc | |
; ######################################################################### | |
.data | |
Format db "%.6G",0 | |
horzBuffer db 32 dup(0) | |
vertBuffer db 32 dup(0) | |
inchASmm qword 25.4f | |
.data? | |
hDC HDC ? | |
cyLogPX qword ? | |
cxLogPX qword ? | |
horz qword ? | |
vert qword ? | |
horz2f qword ? | |
vert2f qword ? | |
.code | |
start: | |
; ######################################################################### | |
Call ScreenSizeInInches | |
Call ScreenSizeInPixels | |
Call ScreenSizeInLogicalPixels | |
inkey | |
exit | |
ScreenSizeInInches proc | |
invoke GetDC,hDC | |
push eax | |
invoke GetDeviceCaps,eax,HORZSIZE | |
push offset horz | |
push eax | |
call dwtoa | |
pop eax | |
push eax | |
invoke GetDeviceCaps,eax,VERTSIZE | |
push offset vert | |
push eax | |
call dwtoa | |
pop eax | |
invoke ReleaseDC,hDC,eax | |
invoke StrToFloat, ADDR horz, ADDR horz2f | |
invoke StrToFloat, ADDR vert, ADDR vert2f | |
finit | |
fld qword ptr [horz2f] | |
fld qword ptr [inchASmm] | |
fdiv | |
fstp qword ptr [horz2f] | |
invoke crt_sprintf,ADDR horzBuffer,ADDR Format,horz2f | |
finit | |
fld qword ptr [vert2f] | |
fld qword ptr [inchASmm] | |
fdiv | |
fstp qword ptr [vert2f] | |
invoke crt_sprintf,ADDR vertBuffer,ADDR Format,vert2f | |
print "Your screen size in inches is " | |
print Addr horzBuffer,34 | |
print " x " | |
print Addr vertBuffer,34,13,10 | |
ret | |
ScreenSizeInInches endp | |
ScreenSizeInPixels proc | |
invoke GetDC,hDC | |
push eax | |
invoke GetDeviceCaps,eax,HORZRES | |
push offset horz | |
push eax | |
call dwtoa | |
pop eax | |
push eax | |
invoke GetDeviceCaps,eax,VERTRES | |
push offset vert | |
push eax | |
call dwtoa | |
pop eax | |
invoke ReleaseDC,hDC,eax | |
print "Your screen size in pixels is " | |
print ADDR horz | |
print " x " | |
print ADDR vert,13,10 | |
ret | |
ScreenSizeInPixels endp | |
ScreenSizeInLogicalPixels proc | |
invoke GetDC,hDC | |
push eax | |
invoke GetDeviceCaps,eax,LOGPIXELSX | |
push offset cxLogPX | |
push eax | |
call dwtoa | |
pop eax | |
push eax | |
invoke GetDeviceCaps,eax,LOGPIXELSY | |
push offset cyLogPX | |
push eax | |
call dwtoa | |
pop eax | |
invoke ReleaseDC,hDC,eax | |
print "Your screen size in logical pixels is " | |
print Addr cxLogPX | |
print " x " | |
print Addr cyLogPX,13,10 | |
ret | |
ScreenSizeInLogicalPixels endp | |
end start | |
; ######################################################################### | |
; Note: my screen res scale was set at 125% when I ran this test: | |
; Your screen size in inches is 23.937" x 13.9764" | |
; Your screen size in pixels is 2048 x 1152 | |
; Your screen size in logical pixels is 96 x 96 | |
; Press any key to continue ... | |
;Here it is at 100%... | |
;Your screen size in inches is 23.937" x 13.9764" | |
;Your screen size in pixels is 2560 x 1440 | |
;Your screen size in logical pixels is 96 x 96 | |
;Press any key to continue ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment