Get Height of Font Used in InputBox?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Sparkon
Posts: 25
Joined: 04 Oct 2016, 15:55

Get Height of Font Used in InputBox?

Post by Sparkon » 25 Mar 2023, 04:26

AutoHotkey's InputBox lets you specify a pixel height for the InputBox. This is especially useful for when you have a long input prompt that will take up multiple lines.

The problem is that the height we want is going to vary depending on the system font, which varies across operating systems and also depends on user settings. I can calculate a proper height for the InputBox if I know the height for a single line of text using that font. But how do you get that font height? My first thought was to use WinAPI's GetSystemMetrics(), but reading through Microsoft's documentation for that function, it is not able to get the height of that font.

So anyone know how to get that font height?

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Get Height of Font Used in InputBox?

Post by Rohwedder » 25 Mar 2023, 05:35

Hallo,
just use a Gui instead of the InputBox. It allows much more design possibilities.

Code: Select all

SetTimer, Gui, -100
InputBox, OutputVar ,,,,250,120,100,100,,, Default
if !ErrorLevel
    MsgBox, You entered:`n%OutputVar%
Else
    MsgBox, Cancel or CloseButton was pressed.
Return
Gui:
Gui, +AlwaysonTop +Resize -MinimizeBox -MaximizeBox 
Gui, Font, s10, Verdana
Gui, Margin, 5, 4
Gui, Add, Edit, y24 w227 h25 vOutputVar, Default
Gui, Add, Button, x25 w60 gOK, OK
Gui, Add, Button, x+60 w60 gGuiClose, Cancel
Gui, Show, x400 y100,% A_ScriptName
Return
OK:
GuiClose:
Gui Submit
if A_GuiControl = OK
    MsgBox, You entered:`n%OutputVar%
else
    MsgBox, Cancel or CloseButton was pressed.
Return

Sparkon
Posts: 25
Joined: 04 Oct 2016, 15:55

Re: Get Height of Font Used in InputBox?

Post by Sparkon » 25 Mar 2023, 11:21

That doesn't answer my question at all. If I wanted to use a custom GUI, I wouldn't have asked this question.

I want to know how to get the height of the InputBox font.

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Get Height of Font Used in InputBox?

Post by Rohwedder » 25 Mar 2023, 13:08

Then let the script measure it:

Code: Select all

SetTimer, BlackPixelSearch, -100
InputBox, OutputVar,, `n`n`t█,,,,,,, 2
Return
BlackPixelSearch:
PixelSearch, X1,Y1,50,50,200,200, 0x000000,, Fast
PixelSearch, X2,Y2,200,200,X1,Y1, 0x000000,, Fast
MsgBox,% "W:" 1+X2-X1 " H:" 1+Y2-Y1

Sparkon
Posts: 25
Joined: 04 Oct 2016, 15:55

Re: Get Height of Font Used in InputBox?

Post by Sparkon » 25 Mar 2023, 15:03

Creating a temporary dialog box to try to measure font height by scanning pixels is just too clunky.

I use AutoHotkey's SysGet or WinAPI's GetSystemMetrics() to directly query Windows for other metrical data like titlebar, icon, or scrollbar height/width in order to create GUIs and dialog boxes with precise dimensions for best visual appearance on the user's system.

Unfortunately, SysGet or GetSystemMetrics() cannot get font height, but there should be some similar way to directly query Windows for that information.
Last edited by Sparkon on 25 Mar 2023, 16:03, edited 1 time in total.

User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Get Height of Font Used in InputBox?

Post by mikeyww » 25 Mar 2023, 16:01

This page has a search form in the top right corner. The following might be a lead; I did not try it. viewtopic.php?t=1979

Jees, I found some more results by searching for them.

viewtopic.php?p=186015#p186015

viewtopic.php?f=5&t=29275&p=137700#p137700

OK. This stuff is for MsgBox. Could it be the same font? Maybe worth checking. Or perhaps there is some connection. I just tried both-- looked the same.

Post Reply

Return to “Ask for Help (v1)”