Skip to content

Instantly share code, notes, and snippets.

@KevinRagsdale
Created December 16, 2013 15:56
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 KevinRagsdale/7989347 to your computer and use it in GitHub Desktop.
Save KevinRagsdale/7989347 to your computer and use it in GitHub Desktop.
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