Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code to determine the current DPI setting. Displays the percentage I should bump up my visual controls by in order to match the users settings.
LOCAL liHDC, liPixelsPerInchX, ;
liPixelsPerInchY, lnFontFactor
DECLARE INTEGER GetDC IN Win32API ;
INTEGER iHDC
DECLARE INTEGER GetDeviceCaps IN WIN32API ;
INTEGER iHDC, INTEGER iIndex
#DEFINE cnLOG_PIXELS_X 88
#DEFINE cnLOG_PIXELS_Y 90
liHDC = GetDC(ThisForm.HWnd)
liPixelsPerInchX = GetDeviceCaps(liHDC, cnLOG_PIXELS_X)
liPixelsPerInchY = GetDeviceCaps(liHDC, cnLOG_PIXELS_Y)
IF liPixelsPerInchX <= 96
** The user has selected "normal" font size
lnFontFactor = 1
ELSE
** The user wants to use large fonts. The
** calculation will determine how large
** (by percentage) the fonts should be.
lnFontFactor = 1 + ((liPixelsPerInchX - 96)/96)
ENDIF
MESSAGEBOX("The DPI 'font factor' is: " + ;
ALLTRIM(TRANSFORM(lnFontFactor)),0,"Font Factor")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment