Jump to content
Sign in to follow this  

Autoit and DPI awareness

Recommended Posts

I'm finding users adjusting the default screen DPI setting far more often in Windows 7 than I ever experienced with Windows XP.

Perhaps the setting is now more prominently displayed or easily found than when is was in the advanced section of the settings tab of the display options window.

Most commercial applications seem to adapt to the DPI value without a glitch, but Autoit only partially conforms to this system-wide setting.

The fonts within controls are affected, yet the overall control dimensions are not.  The result are labels, buttons, etc, with txt that is truncated or unreadable. Some special controls or API functions in Autoit, like calendar, are also affected by the DPI setting.  

I've overridden non-default DPI settings by calling this at the top of programs:

Func GetDPI_Ratio()
    Local $hWnd = 0
    Local $hDC = DllCall("user32.dll", "long", "GetDC", "long", $hWnd)
    Local $aRet = DllCall("gdi32.dll", "long", "GetDeviceCaps", "long", $hDC[0], "long", 90)
    $hDC = DllCall("user32.dll", "long", "ReleaseDC", "long", $hWnd, "long", $hDC)
    If $aRet[0] = 0 Then $aRet[0] = 96
    Return $aRet[0] / 96

It returns an $iDPI_Ratio global such as 1 or 1.25. I then replace all calls to GUISetFont() and GUICtrlSetFont() with calls to user functions like GUISetFont_DPI() and GUICtrlSetFont_DPI() which apply the $iDPI_Ratio variable as a divisor to the font size parameter like this:

Func GUISetFont_DPI($isize, $iweight = "", $iattribute = "", $sfontname = "")
    GUISetFont($isize / $iDPI_Ratio, $iweight, $iattribute, $sfontname)

I'm still left with a few uncorrected issues like calendar controls.  I considered a bugtracker to request an extra parm for GUISetFont() and GUICtrlSetFont(), that would act as a DPI divisor and default to 1.  That would greatly simplify programatically suppressing a non-standard DPI setting. Then I wonder if perhaps the goal should be to move in the opposite direction... that of making Autoit fully DPI-aware?

It appears the available values for the DPI setting are:


1.00 (default)




Share this post

Link to post
Share on other sites

I've started using Windows on a high-dpi screen and I know what you mean. It's easy to tag the exes with the DPIAwareness manifest but there's a lot of testing/work to make it look right. The only file I've tagged so far is Aut2Exe (Beta) which looks OK - but normal GUIs fell to pieces so its one for the furture.

Share this post

Link to post
Share on other sites

Is that a sign of hesitation between future and torture?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...