Jump to content

Automatic control resizing based on DPI


rmorrow
 Share

Recommended Posts

All of the GUI scripts I've seen are designed for one DPI setting and do not adjust for another DPI, specifically 120DPI. Has anyone seen a UDF or just a "smarter" way of creating a GUI that would automatically adjust a control and window's size based on screen DPI? What I'm thinking of would involve designing your GUI for 96 DPI, then throwing it at a function that would adjust the window size and move/resize all controls based on a difference DPI.

For instance, if my DPI is 120, a script would automatically make the window 25% larger (because 120 is 25% larger than 96), then loop through all controls and resize them to 25% larger (both X and Y), then move them so they don't overlap.

Perhaps a properly designed GUI would rely on the "auto-sizing" features and simply adjust the window's size by the necessary 25% and allow the built-in resizing to handle the rest. I think this would require calling the GUICtrlSetResizing function for every control, and then resizing the window.

Link to comment
Share on other sites

What I'm thinking of would involve designing your GUI for 96 DPI, then throwing it at a function that would adjust the window size and move/resize all controls based on a difference DPI.

<{POST_SNAPBACK}>

You're on the right track. I've been doing this for a while. Your post made me take a look at it and to search the forum. I found some code, by this-is-me and Larry, using "GetDeviceCaps" to obtain the current DPI. I'd been reading a registry key which someone reported returns zero on some Windows platforms, so maybe GetDeviceCaps will be better.

Attached is a cleaned and updated version of the script. Please let me know if it works for you. At the top of the file, I commented an example. All you should have to do is temporarily uncomment and run it.

The script requires a version of AutoIt3.1.1 with the DLLCall function. I am running v3.1.1.67. I just checked and v3.1.1.68 was posted 12-Aug-2005.

GetDPI.au3

Phillip

Link to comment
Share on other sites

Just curious - how is DPI relavent to AutoIt? AutoIt GUI uses pixels, not points to measure control sizes, so aren't all control sizes absolute?

Link to comment
Share on other sites

You're on the right track.  I've been doing this for a while.  Your post made me take a look at it and to search the forum.  I found some code, by this-is-me and Larry, using "GetDeviceCaps" to obtain the current DPI.  I'd been reading a registry key which someone reported returns zero on some Windows platforms, so maybe GetDeviceCaps will be better.

Attached is a cleaned and updated version of the script.  Please let me know if it works for you.  At the top of the file, I commented an example.  All you should have to do is temporarily uncomment and run it.

The script requires a version of AutoIt3.1.1 with the DLLCall function.  I am running v3.1.1.67.  I just checked and v3.1.1.68 was posted 12-Aug-2005.

GetDPI.au3

Screen shot at 96 DPI

Screen shot at 120 DPI

Edited to include screen shots.

<{POST_SNAPBACK}>

Phillip

Link to comment
Share on other sites

Just curious - how is DPI relavent to AutoIt?  AutoIt GUI uses pixels, not points to measure control sizes, so aren't all control sizes absolute?

<{POST_SNAPBACK}>

Because the DPI setting affects the size of the font within the GUI, while the dimensions of the GUI remain the same. To compensate, the dimensions of the GUI must be adjusted by the ratio between 96 DPI and the current DPI value (the larger the DPI, the larger the ratio).

For example, with DPI set to 96, assume a GUI, whose width is 96, containing one Label that fits precisely within the GUI borders with no space left over. At 96 DPI the GUI and Label would be precisely 1" wide. However, with the same GUI dimensions and DPI set to 120, it would take 120 pixels to equal 1". While Windows adjusted the font to suit 120 DPI, the GUI dimensions are not affected. The result is the GUI is too small for the Label.

To see the effect for yourself, run the example script wit DPI set to 96 and again at 120. Both GUI's should look okay (because the script compensated for the current DPI) and differ only in size. While at 120 DPI, revise the coding in the example to force variable $iDPIRat to equal 1:

$iDPIRat = $a1[2]
    $iDPIRat = 1

Run the script again. Is the GUI okay, or did the text run out of room and truncate at the word "returned"? Also note the lack of space between the edge of the button and the word "Close", and the GUI title completely fills the Title Bar.

Phillip

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...