Setting a custom aspect ratio on fixed window Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

Setting a custom aspect ratio on fixed window

Post by doubledave22 » 01 Dec 2021, 12:40

Is is possible to override a window's built in aspect ratio and set the height and width myself? I am aware that winmove can do this however when the window's own aspect ratio is fixed, this window will set it's height automatically.

For example, the window is 600x400 and let's say it has a fixed aspect ratio of 1.5:1. If I use winmove to do something like 1000x400 it will automatically set the height to 666.666 instead of 400 since it's fixed.

Are there any windows api calls to remove the fixed h:w ratio on a specific window and override it to set my own? I don't want to use winset, region to accomplish this. Thanks!

doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

Re: Setting a custom aspect ratio on fixed window

Post by doubledave22 » 09 Jan 2022, 10:42

Still looking for help on this. It's really hard to search anywhere on the topic since everyone is trying to figure out the opposite solution (maintaining a fixed ratio). What I want is to size a resizable but fixed aspect ratio window to my own custom size/ratio.

Do I need to hook and process wm_sizing or is there an easier solution?

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Setting a custom aspect ratio on fixed window

Post by boiler » 09 Jan 2022, 10:48

It would seem that if it’s reverting to a certain aspect ratio, it’s because the application is doing that itself in its display update routine, not because of something Windows is doing. So if you want to change that, you might have to inject your modification of that routine into their code, which is a pretty advanced programming technique. I would also not expect great results since their routine is obviously not meant to fill a window of a different aspect ratio.

doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

Re: Setting a custom aspect ratio on fixed window

Post by doubledave22 » 09 Jan 2022, 11:03

Ok thanks. In my research on the topic one of my competitors who's able to do this wrote this:
"What's the function that allows you to resize by overriding the aspect ratio? Is it a win32?"

Yes, this is some combination of Win API functions.
I was hoping I could do it via API instead of hooking unless the two arent mutually exclusive

doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

Re: Setting a custom aspect ratio on fixed window  Topic is solved

Post by doubledave22 » 17 Jan 2022, 15:09

@boiler turns out the solution was somewhat simple. SetWindowPos with SWP_NOSENDCHANGING flag.

Code: Select all


SetWinMove(hwnd, X := "", Y := "", W := "", H := "")
{
	Static SWP_NOSENDCHANGING = 0x0400
		 , SWP_NOZORDER = 0x0004
		 , SWP_NOACTIVATE = 0x0010
		 , SWP_NOMOVE = 0x0002
		 , SWP_NOSIZE = 0x0001
	
	Flags := SWP_NOSENDCHANGING|SWP_NOZORDER|SWP_NOACTIVATE
	
	if (X = "" and Y = "")
		Flags += SWP_NOMOVE
	
	if (W = "" and H = "")
		Flags += SWP_NOSIZE
	
	DllCall("SetWindowPos","uint", hwnd
						  ,"uint",
						  ,"int", X
						  ,"int", Y
						  ,"int", W
						  ,"int", H
						  ,"uint",Flags)
}

I think I did the flag math correctly but you can let me know if I did anything wrong. Anyway, thought this may be useful for anyone who's run into this issue

guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: Setting a custom aspect ratio on fixed window

Post by guest3456 » 03 Feb 2022, 12:41

doubledave22 wrote:
17 Jan 2022, 15:09
@boiler turns out the solution was somewhat simple. SetWindowPos with SWP_NOSENDCHANGING flag.

Code: Select all


SetWinMove(hwnd, X := "", Y := "", W := "", H := "")
{
	Static SWP_NOSENDCHANGING = 0x0400
		 , SWP_NOZORDER = 0x0004
		 , SWP_NOACTIVATE = 0x0010
		 , SWP_NOMOVE = 0x0002
		 , SWP_NOSIZE = 0x0001
	
	Flags := SWP_NOSENDCHANGING|SWP_NOZORDER|SWP_NOACTIVATE
	
	if (X = "" and Y = "")
		Flags += SWP_NOMOVE
	
	if (W = "" and H = "")
		Flags += SWP_NOSIZE
	
	DllCall("SetWindowPos","uint", hwnd
						  ,"uint",
						  ,"int", X
						  ,"int", Y
						  ,"int", W
						  ,"int", H
						  ,"uint",Flags)
}

I think I did the flag math correctly but you can let me know if I did anything wrong. Anyway, thought this may be useful for anyone who's run into this issue
sweet ill have to try this. but another problem to consider is whether the application graphics will scale correctly with non-standard proportions

you might want to check if you need |= instead of += for those flag operations


doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

Re: Setting a custom aspect ratio on fixed window

Post by doubledave22 » 03 Feb 2022, 13:16

Yeah each app seems to process this differently (or some not at all). Some literally stretch the window, others process their controls as they should, others just create dead space, and some just don't respond at all. I am just gonna use it apps that respond like the first two cases.

I will check out the |= vs the +=. In my use case I'm sending all 4 params but it seemed to prevent moving or resizing when i tested without some of the params. Maybe I just got lucky

Post Reply

Return to “Ask for Help (v1)”