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

来源:互联网 发布:淘宝人肉搜索服务 编辑:程序博客网 时间:2024/06/04 19:29
From:http://www.autohotkey.com/community/viewtopic.php?t=3429 

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:
Code:
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:
Code:
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...

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()
{
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

  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
}



原创粉丝点击