measure Menu/ToolTip/GUI dimensions before showing

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

measure Menu/ToolTip/GUI dimensions before showing

18 Feb 2017, 14:12

Are there any scripts/functions for measuring a GUI window before it is shown.
E.g. the ToolTip command or the Menu command.
For example, so you can centre the ToolTip, or decide whether
to place a menu above/below the cursor etc.

I tried DrawText on ToolTips, to measure the text dimensions,
versus the ToolTip window size, but when I increased
the ToolTip font via WM_SETFONT, the number of extra 'border' pixels did not stay constant.

Btw what font does ToolTip use?
On my system it was: Segoe UI, size 9, regular,
which I found out via WM_GETFONT and GetObject.
It doesn't seem to be:
- the icon label font (SPI_GETICONTITLELOGFONT)
- or one of Caption,SmCaption,Menu,Status,Message (SPI_GETNONCLIENTMETRICS) (see NONCLIENTMETRICS structure)
- or SYSTEM_FONT (System, size 12?, bold) (it returned a height of positive 16, when the height is usually given as a negative number)
- or DEFAULT_GUI_FONT (MS Shell Dlg, size 8, regular) (see (GetStockObject for DEFAULT_GUI_FONT/SYSTEM_FONT).

I checked in the source code, and just me's ToolTipEx, and Lexikos's ToolTipFont, but didn't find the answer.
Thank you for reading.
Last edited by jeeswg on 18 Feb 2017, 15:44, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: measure GUI dimensions before showing

18 Feb 2017, 14:58

jeeswg wrote:Are there any scripts/functions for measuring a GUI window before it is shown.
See, Gui,Show, Hide, WinGetPos, DetectHiddenWindows
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: measure Menu/ToolTip/GUI dimensions before showing

18 Feb 2017, 16:02

Some problems with workaround attempts for Menu/ToolTip commands,
to show a Menu/ToolTip offscreen, and retrieve dimensions, prior to showing onscreen:

Code: Select all

q::
;PROBLEM: attempt to show ToolTip offscreen but appears in bottom-left corner
ToolTip, HELLO, 0, % A_ScreenHeight
WinGet, hWnd, ID, ahk_class tooltips_class32
WinGetPos, , , vPosW, vPosH, ahk_id %hWnd%
Sleep 1000
WinMove, ahk_id %hWnd%, , % (A_ScreenWidth-vPosW)/2, % (A_ScreenHeight-vPosH)/2
MsgBox % vPosW " " vPosH
ToolTip

Menu, EditMenu, Add, &My Item, MyItem
Menu, EditMenu, Add ;------------------------------
Menu, EditMenu, Add, &Undo, EditUndo
Menu, EditMenu, Add ;------------------------------
Menu, EditMenu, Add, Cu&t, EditCut
Menu, EditMenu, Add, &Copy, EditCopy
Menu, EditMenu, Add, &Paste, EditPaste
Menu, EditMenu, Add, &Delete, EditDelete
Menu, EditMenu, Add ;------------------------------
Menu, EditMenu, Add, Select &All, EditSelectAll

;PROBLEM: it seems that while the Menu is showing SetTimer doesn't work
SetTimer, GetMenuPos, -1
;PROBLEM: attempt to show Menu offscreen but appears in bottom-left corner
Menu, EditMenu, Show, 0, % A_ScreenHeight
WinMove, ahk_id %hWnd%, , % (A_ScreenWidth-vPosW)/2, % (A_ScreenHeight-vPosH)/2
Sleep 1000
MsgBox % vPosW " " vPosH
JEE_RetX()

GetMenuPos:
ToolTip GetMenuPos
WinGet, hWnd, ID, ahk_class #32768
WinGetPos, , , vPosW, vPosH, ahk_id %hWnd%
Return
@Helgef Thanks
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: measure Menu/ToolTip/GUI dimensions before showing

18 Feb 2017, 18:55

jeeswg wrote:Some problems with workaround attempts for Menu/ToolTip commands,
to show a Menu/ToolTip offscreen, and retrieve dimensions, prior to showing onscreen:
Sadly, I see it blink

Code: Select all

#singleinstance force
#warn

Coordmode Tooltip, Screen

Tooltip % "Hello World!`nMultiline", 0, 0
WinGet hwnd, ID, ahk_class tooltips_class32
DllCall("ShowWindow", "Ptr", hwnd, "Uint", 0) ; SW_HIDE
VarSetCapacity(rec,4*A_PtrSize)
res := DllCall("GetWindowRect", "Ptr", hwnd, "Ptr", &rec)
posX := NumGet(rec, 0, "UInt")
posY := NumGet(rec, 4, "UInt")
width := NumGet(rec, 8, "UInt") - posX
height := NumGet(rec, 12, "UInt") - posY
msgbox % "Width -> " . width . "`nHeight -> " . height

Return

F1::reload

Esc::
ExitApp
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: measure Menu/ToolTip/GUI dimensions before showing

03 Jun 2018, 23:14

One useful Winapi function is AdjustWindowRect/AdjustWindowRectEx, mentioned here:
slightly-improved dialogs - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 86#p208686
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 153 guests