Get minimum window dimensions

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jc1593243
Posts: 2
Joined: 28 Aug 2017, 16:06
Contact:

Get minimum window dimensions

28 Aug 2017, 16:16

Is there a way to get the minimum dimensions for a given window? I don't want to change or override these values, just to be able to get and display the minimum height and width to which a user can drag a window.

I thought this would be straightforward, but I've been searching for days with no luck. I do see a number of posts discussing how to override these minimum limits using some combinations of things like SysGet, SendMessage, WM_MINMAXINFO, SM_CYMAXTRACK, etc but frankly they're over my head & I can't even tell if I'm on the right track...some of these also seem to refer to an OS-wide minimum value, so I'm not sure if they can be used to get minimum values for specific applications?
User avatar
Capn Odin
Posts: 1352
Joined: 23 Feb 2016, 19:45
Location: Denmark
Contact:

Re: Get minimum window dimensions

28 Aug 2017, 20:36

I doubt that this is correct, as I haven't really researched it, but it works for File Explore.

Code: Select all

WM_GETMINMAXINFO := 0x0024

x::
	info := GetMinMaxInfo()
	MsgBox, % info["min_x"] "`n" info["min_y"] "`n" info["max_y"] "`n" info["max_y"]
return

GetMinMaxInfo() {
	Global WM_GETMINMAXINFO
	Static MINMAXINFO := 0, Dummy := NumPut(VarSetCapacity(MINMAXINFO, 40 + (32 << !!A_IsUnicode)), MINMAXINFO, 0, "UInt")
	NumPut(0, MINMAXINFO, 24, "Int")
	NumPut(0, MINMAXINFO, 28, "Int")
	NumPut(0, MINMAXINFO, 32, "Int")
	NumPut(0, MINMAXINFO, 36, "Int")
	SendMessage, % WM_GETMINMAXINFO, , &MINMAXINFO, , A
	return {"min_x" : NumGet(MINMAXINFO, 24, "Int"), "min_y" : NumGet(MINMAXINFO, 28, "Int"), "max_x" : NumGet(MINMAXINFO, 32, "Int"), "max_y" : NumGet(MINMAXINFO, 36, "Int")}
}
Please excuse my spelling I am dyslexic.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Get minimum window dimensions

28 Aug 2017, 21:22

I've produced various bits of relevant code.

Code: Select all

q:: ;window get min/max size limits
WinGet, hWnd, ID, A
VarSetCapacity(MINMAXINFO, 40, 0)
SendMessage, 0x24,, % &MINMAXINFO,, % "ahk_id " hWnd ;WM_GETMINMAXINFO := 0x24
vMinX := NumGet(MINMAXINFO, 24, "Int") ;ptMinTrackSize
vMinY := NumGet(MINMAXINFO, 28, "Int")
vMaxX := NumGet(MINMAXINFO, 32, "Int") ;ptMaxTrackSize
vMaxY := NumGet(MINMAXINFO, 36, "Int")
MsgBox, % vMinX " " vMinY "`r`n" vMaxX " " vMaxY
return
;e.g. Notepad min (Windows 7): 0 0
;e.g. Notepad max (Windows 7): 0 0
;e.g. Internet Explorer 11: 250 100
;e.g. Internet Explorer 11: 0 0

w:: ;get system-wide min/max size defaults
SysGet, vMinX, 34 ;SM_CXMINTRACK := 34
SysGet, vMinY, 35 ;SM_CYMINTRACK := 35
SysGet, vMaxX, 59 ;SM_CXMAXTRACK := 59
SysGet, vMaxY, 60 ;SM_CYMAXTRACK := 60
MsgBox, % vMinX " " vMinY "`r`n" vMaxX " " vMaxY
return
;e.g. system min: 174 38
;e.g. system max: 1300 740

e:: ;window resize to get min/max sizes, then restore original size
WinGet, hWnd, ID, A
WinGetPos,,, vWinW, vWinH, % "ahk_id " hWnd
WinMove, % "ahk_id " hWnd,,,, 0, 0
WinGetPos,,, vMinX, vMinY, % "ahk_id " hWnd
WinMove, % "ahk_id " hWnd,,,, 10000, 10000 ;arbitrary values
WinGetPos,,, vMaxX, vMaxY, % "ahk_id " hWnd
WinMove, % "ahk_id " hWnd,,,, % vWinW, % vWinH
MsgBox, % vMinX " " vMinY "`r`n" vMaxX " " vMaxY
return
Btw if you were going to give anyone a solved tick please give it to Capn Odin, because he's done all the hard work with the window message and the struct. Cheers.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
jc1593243
Posts: 2
Joined: 28 Aug 2017, 16:06
Contact:

Re: Get minimum window dimensions

29 Aug 2017, 09:32

Thanks to both Capn Odin and jeeswg. Both bits of code are interesting, and while I can't say I understand either 100% I was able to mostly get them working. I actually had a bit of better luck with jeeswg's, although it seems like the min numbers it returns still aren't the actual minimum window size:

Code: Select all

q:: ;window get min/max size limits
WinGet, hWnd, ID, A
VarSetCapacity(MINMAXINFO, 40, 0)
SendMessage, 0x24,, % &MINMAXINFO,, % "ahk_id " hWnd ;WM_GETMINMAXINFO := 0x24
vMinX := NumGet(MINMAXINFO, 24, "Int") ;ptMinTrackSize
vMinY := NumGet(MINMAXINFO, 28, "Int")
WinMove, A,, 0, 0, %vMinX%, %vMinY%
return
If I immediately WinMove the window using the returned values as dimensions, after the resize I'm still able to manually drag the window to a yet smaller size. From searching around, it seems like the "ptMinTrackSize" values that Windows returns might not be "smallest size you can resize to" but rather something like "smallest size for the client area of a given window, to which you have to add sizes of various padding elements like titlebars or window chrome in order to determine actual min size"

Any thoughts on that? Are there specific other values that one would need to retrieve and add to the values returned by the above code, in order to determine the total window minimum size?

Thanks again for any help you can offer. Man, I really didn't think that this little bit would be the part of the project that was so challenging...
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Get minimum window dimensions

29 Aug 2017, 10:59

From my testing, it appears that if you took the individual window's limits, and the system-wide limits, and took the more restrictive values (i.e. the larger min values, and the smaller max values), that gave you the actual minimum/maximum window sizes, for the entire window (and not the client area). Although I don't guarantee this.

You might like to mention what Windows version you're using.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
lmstearn
Posts: 694
Joined: 11 Aug 2016, 02:32
Contact:

Re: Get minimum window dimensions

08 Jan 2021, 10:10

FWIW, had no luck with any of the MinTrackSize values. The window height will size to 2 pixels, and the width sizes to the menu bar height, as if they have the things round the wrong way. In any case, no values given it make any difference at all.
Edit: Don't think It is a global setting by default- so maybe that's the issue is that it has to be updated with OnMessage .
The only other possible explanation is there is something off in the monitor setup- if this isn't a primary monitor here, MINMAXINFO is the only function that says so. :(
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ccqcl and 323 guests