Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

How to detect Normal or Large font size settings (DPI)


  • Please log in to reply
4 replies to this topic
jordis
  • Members
  • 81 posts
  • Last active: Aug 22 2014 01:56 PM
  • Joined: 30 Jul 2004
Hi
I created a script which uses a GUI, but I had a problem: if the user had the "Large Fonts" set in the Display settings, the GUI would present truncations all around.
Although AHK allows for auto-resize and auto-placement of GUI controls, I wanted to have full control of their exact position in the GUI.
After unsuccessful and/or confusing google searches, I found out that the actual font size is specified in a registry key:
HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics\AppliedDPI
so I created a tiny function which returns 0 is the user is using normal (default) font size or 1 if the user is using large font size:
if checkDPIsize()=0
   msgbox, You are using normal font settings
else
   msgbox, You are using LARGE font settings
exitapp

; This is the function:
; returns 0 if normal font size or 1 if LARGE font size
checkDPIsize()
{
RegRead, DPI_value, HKEY_CURRENT_USER, Control Panel\Desktop\WindowMetrics, AppliedDPI
if errorlevel=1 ; the reg key was not found - it means default settings
   return 0
if DPI_value=96 ; 96 is the default font size setting
   return 0
if DPI_value>96 ; A higher value should mean LARGE font size setting
   return 1
}
Note that if the registry key does not exist, it means that the deaulft settings are being used.

By knowing whether the user is using normal or large fonts, I can act accordingly in the GUI definition section...

This works in Win2000 & WinXP, I don't know about earlier versions...
I though that it might be worth sharing, in case other AHKers were facing the same problem...

jordi

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
That's very useful info. Thanks for posting it along with your elegant solution.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Cool! Not knowing this registry entry I wrote my GUI scripts all specifying the text font and its size. This avoids cropping, but in high screen resolution the GUI window becomes too small.

Joy2DWorld
  • Members
  • 562 posts
  • Last active: Jun 30 2014 07:48 PM
  • Joined: 04 Dec 2006
if helpful,

getDPI(options = "") {

if (options = "REG") {
RegRead, DPI, HKEY_CURRENT_USER, Control Panel\Desktop\WindowMetrics, AppliedDPI
return (errorlevel = 1) ? 96 : DPI
}

x := dllcall("GetDC")
dpi := dllcall("GetDeviceCaps", UINT, x , UINT, 88)
dllcall("ReleaseDC",INT, 0, UINT, x)

return dpi ? dpi : 96
}


Joyce Jamce

  • Guests
  • Last active:
  • Joined: --
A small mod to the original post by jordis will allow detection on older win32 os systems (win95, win98, winME).

if checkDPIsize()=0 
   msgbox, You are using normal font settings 
else 
   msgbox, You are using LARGE font settings 
exitapp 

; This is the function: 
; returns 0 if normal font size or 1 if LARGE font size 
checkDPIsize() 
{
[color=blue]if A_OSVersion in WIN_95,WIN_98,WIN_ME  ; check if old win32 OS
  RegRead, DPI_value, HKEY_CURRENT_CONFIG, Display\Settings, DPILogicalX
; RegRead, DPI_value, HKEY_LOCAL_MACHINE, Config\0001\Display\Settings, DPILogicalX ; value is also stored here
else[/color]
  RegRead, DPI_value, HKEY_CURRENT_USER, Control Panel\Desktop\WindowMetrics, AppliedDPI 
if errorlevel=1 ; the reg key was not found - it means default settings 
   return 0 
if DPI_value=96 ; 96 is the default font size setting 
   return 0 
if DPI_value>96 ; A higher value should mean LARGE font size setting 
   return 1 
}