Understanding Winmove properly

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Understanding Winmove properly

01 Aug 2021, 17:27

I would like Potplayer to take up 75% of my screen on right hand side, and Evernote to take up the remaining 25%.

1. How do I code it such that it takes all remaining space?
2. I don't fully understand the Winmove parameters - I used winspy to check for the coordinates of the top-left I want to pin X,Y at but after using it, it is not pinning at the right place. why?
3. Even specifying the height and width at 2000, 2000, it doesn't maximize the window. why is that so?

Thank you.


Code: Select all

#left:: ;side by side with pot player. Screen resolution is 2560x1440
Numpad2::
Sendinput 9 ; Side by side with Evernote for Note Taking
WinMove, ahk_class PotPlayer64, , , 0, 670, 2000, 2000 ; The X and Y coordinates (in pixels) of the upper left corner of the target window's new location, which can be expressions. The upper-left pixel of the screen is at 0, 0.
WinMove, ahk_class ENSingleNoteView, , , 0, 680 
return
gregster
Posts: 8886
Joined: 30 Sep 2013, 06:48

Re: Understanding Winmove properly

01 Aug 2021, 17:32

Looks like you have the parameters wrong. x and y should be third and fourth, not fourth and fifth.
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: Understanding Winmove properly

01 Aug 2021, 18:46

ah got it. how do I solve Q1 and also whether possible to indicate % of screen width to take up per program?
User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: Understanding Winmove properly

01 Aug 2021, 18:52

milkygirl90 wrote:
01 Aug 2021, 18:46
ah got it. how do I solve Q1 and also whether possible to indicate % of screen width to take up per program?
Easy.

Code: Select all

; 75% of prime monitor
Width := A_ScreenWidth * 0.75
Height := A_ScreenHeight * 0.75

WinMove,,, width, height

; 10%

Width := A_ScreenWidth * 0.1
Height := A_ScreenHeight * 0.1

WinMove,,, width, height
HTH
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: Understanding Winmove properly

01 Aug 2021, 19:20

don't mind my silly questions.. but I'm still getting tons of gaps that I have to adjust manually...

Also, the browser doesn't resize if it was originally in Maximized mode.

Code: Select all

#left:: ;side by side with  Browsers 
; 75% of prime monitor
Width75 := A_ScreenWidth * 0.75
FullHeight := A_ScreenHeight
FullWidth := A_ScreenWidth
Width25 := A_ScreenWidth * 0.25
Height25 := A_ScreenHeight * 0.25
WinMove, ahk_group MyBrowsers,,Width25, 0 , width75, FullHeight
WinMove, ahk_class ENSingleNoteView,,0 ,0 , width25, FullHeight
WinActivate, ahk_class ENSingleNoteView
return
image.png
image.png (716.52 KiB) Viewed 1009 times
User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: Understanding Winmove properly

01 Aug 2021, 19:26

milkygirl90 wrote:
01 Aug 2021, 19:20
don't mind my silly questions.. but I'm still getting tons of gaps that I have to adjust manually...

Code: Select all

#left:: ;side by side with  Browsers 
; 75% of prime monitor
Width75 := A_ScreenWidth * 0.75
FullHeight := A_ScreenHeight
FullWidth := A_ScreenWidth
Width25 := A_ScreenWidth * 0.25
Height25 := A_ScreenHeight * 0.25
WinMove, ahk_group MyBrowsers,,Width25, 0 , width75, FullHeight
WinMove, ahk_class ENSingleNoteView,,0 ,0 , width25, FullHeight
WinActivate, ahk_class ENSingleNoteView
return
image.png
It looks like it is due to the way your windows get a border / title / caption.

On my system there is a little border around all 4 sides. Yours seems to be missing the border, but is still using the spacing.

Work out how wide the border is and add that from your width

Code: Select all


Border := 5

Width := A_ScreenWidth * 0.75

width += Border * 2


Or something like that.
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: Understanding Winmove properly

01 Aug 2021, 19:55

rightfully if I use

Code: Select all

FullWidth := A_ScreenWidth
it should use the full width yeah?

I tried adjusting using borders but I'm still having gaps..
User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: Understanding Winmove properly

01 Aug 2021, 20:07

milkygirl90 wrote:
01 Aug 2021, 19:55
rightfully if I use

Code: Select all

FullWidth := A_ScreenWidth
it should use the full width yeah?
Yes.
milkygirl90 wrote:
01 Aug 2021, 19:55
I tried adjusting using borders but I'm still having gaps..
This is likely due to you not repositioning the window with the border offset.

Pseudo code:

Code: Select all


Border := 5

;Win 1
;**********************************
XPos := 0 - Border
Width := A_ScreenWidth * 0.25
Width += ( 2 * Border )
Winmove, XPOS ,, Width

;Win 2
;**********************************
XPos := ( Width - ( 2 * Border ) ) - Border
Width := A_ScreenWidth * 0.75
Width += ( 2 * Border )
Winmove, XPOS ,, Width



HTH
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: Understanding Winmove properly

01 Aug 2021, 20:13

still not getting it.. ☹️

Code: Select all

#left:: ;side by side with  Browsers 
; 75% of prime monitor
Border := 10
XPos := 0 - Border
Width75 := A_ScreenWidth * 0.75
Width75 += ( 2 * Border )
FullHeight := A_ScreenHeight
FullWidth := A_ScreenWidth
Width25 := A_ScreenWidth * 0.25
Width25 += ( 2 * Border )
Height25 := A_ScreenHeight * 0.25
WinMove, ahk_group MyBrowsers,,Width25, 0 , Width75, FullHeight
WinMove, ahk_class ENSingleNoteView,,XPos ,0 , Width25, FullHeight
WinActivate, ahk_class ENSingleNoteView
return
User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: Understanding Winmove properly

01 Aug 2021, 20:32

You would need the xpos for each window.


The first window you position at -10 ( 0 - border ) That should put the first window up against the left side of the screen.
The width of that window should be some % + 2 time the width of the border. With that, the first window should look like it is filling the space that was missing because of the lack of visible borders.

For the second window, you position the xpos to be the "Real" width of the first window ( you had added fake borders now you take them back off ) minus the border. Or you can take the screens width and subtract the second windows width, then further subtract the border.
As for the width of the second window, to get it to fill the space you need to add the fake borders to the width.

Code: Select all


Border := 5

;Win 1
;**********************************
XPos := 0 - Border     					; Put the first window off the screen a bit (the width of the border)

Width := A_ScreenWidth * 0.25 			;Get the width
Width += ( 2 * Border )  				;Alter the width to make up for the missing borders.
Winmove, XPOS ,, Width  				;Move the window

;Win 2
;**********************************
XPos := ( Width - ( 2 * Border ) ) - Border  	;Put the second window to be where it would be if it had borders, and then subtract the missing border.
Width := A_ScreenWidth * 0.75 			;Get the width
Width += ( 2 * Border )				;Alter the width to make up for the missing borders.
Winmove, XPOS ,, Width				;Move the window

User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: Understanding Winmove properly

01 Aug 2021, 20:36

If it's not clear. Your window still has borders, you just can't see them, but they are there.
User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: Understanding Winmove properly

01 Aug 2021, 21:21

Almost there.

With the updated script, it seems to be ignoring my taskbar (on right hand side) and even adjusting the XPos doesn't shift the window at all.

2ⁿᵈ issue is that when maximized, the browser does not move at all.

Code: Select all

#left:: ;side by side with  Browsers 
; 75% of prime monitor
Border := 10
XPos1 := 0 - Border
XPos2 := ( Width - ( 2 * Border ) ) - Border
Width75 := (A_ScreenWidth * 0.75)
Width75 -= ( 5 * Border )
FullHeight := A_ScreenHeight
FullWidth := A_ScreenWidth
Width25 := A_ScreenWidth * 0.25
Width25 += ( 2 * Border )
Height25 := A_ScreenHeight * 0.25
WinMove, ahk_group MyBrowsers,,XPos2, 0 , Width75, FullHeight
WinMove, ahk_class ENSingleNoteView,,XPos1, 0 , Width25, FullHeight
WinActivate, ahk_class ENSingleNoteView
return
image.png
(101.15 KiB) Downloaded 184 times
User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: Understanding Winmove properly

01 Aug 2021, 21:43

milkygirl90 wrote:
01 Aug 2021, 21:21
Almost there.

With the updated script, it seems to be ignoring my taskbar (on right hand side) and even adjusting the XPos doesn't shift the window at all.
From your code

Code: Select all

#left:: ;side by side with  Browsers 
; 75% of prime monitor
Border := 10
XPos1 := 0 - Border
XPos2 := ( Width - ( 2 * Border ) ) - Border

...
I can see that you are trying to set XPos2 to use "Width" before it has been set.

As for the taskbar.

You should use the work area for the screen instead of A_ScreenWidth
You can get the work area like this.

Code: Select all

SysGet, WorkArea, MonitorWorkArea , 1

msgbox, % "X1: " WorkAreaLeft "`nY1: " WorkAreaTop "`nX2: " WorkAreaRight "`nY2: " WorkAreaBottom

WorkWidth := WorkAreaRight - WorkAreaLeft
Then add it in like this.

Code: Select all


SysGet, WorkArea, MonitorWorkArea , 1
WorkWidth := WorkAreaRight - WorkAreaLeft
Border := 5

;Win 1
;**********************************
XPos := 0 - Border     					; Put the first window off the screen a bit (the width of the border)

Width := WorkWidth * 0.25 			;Get the width
Width += ( 2 * Border )  				;Alter the width to make up for the missing borders.
Winmove, XPOS ,, Width  				;Move the window

;Win 2
;**********************************
XPos := ( Width - ( 2 * Border ) ) - Border  	;Put the second window to be where it would be if it had borders, and then subtract the missing border.
Width := WorkWidth * 0.75 			;Get the width
Width += ( 2 * Border )				;Alter the width to make up for the missing borders.
Winmove, XPOS ,, Width				;Move the window

User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: Understanding Winmove properly

01 Aug 2021, 22:06

ah......... I still can't get it to work. modified my own and there's now gaps at the bottom, overlap on the right side.

tried with yours but it didn't move at all..

Code: Select all

/*#left:: ;side by side with  Browsers 
; 75% of prime monitor
SysGet, WorkArea, MonitorWorkArea , 1
WorkWidth := WorkAreaRight - WorkAreaLeft
Width75 := (WorkWidth * 0.75)
Width75 -= ( 5 * Border )
Border := 10
XPos1 := 0 - Border
XPos2 := ( Width - ( 2 * Border ) ) - Border
FullHeight := A_ScreenHeight
FullWidth := WorkWidth
Width25 := WorkWidth * 0.25
Width25 += ( 2 * Border )
Height25 := A_ScreenHeight * 0.25
WinMove, ahk_class ENSingleNoteView,,XPos1, 0 , Width25, FullHeight
WinMove, ahk_group MyBrowsers,,XPos2, 0 , Width75, FullHeight
WinActivate, ahk_class ENSingleNoteView
return
*/

#left::
SysGet, WorkArea, MonitorWorkArea , 1
msgbox, % "X1: " WorkAreaLeft "`nY1: " WorkAreaTop "`nX2: " WorkAreaRight "`nY2: " WorkAreaBottom
WorkWidth := 2465 - 0
Border := 5

;Win 1
;**********************************
XPos := 0 - Border     					; Put the first window off the screen a bit (the width of the border)
Width := WorkWidth * 0.25 			;Get the width
Width += ( 2 * Border )  				;Alter the width to make up for the missing borders.
Winmove, ahk_class ENSingleNoteView, XPOS ,, Width  				;Move the window

;Win 2
;**********************************
XPos := ( Width - ( 2 * Border ) ) - Border  	;Put the second window to be where it would be if it had borders, and then subtract the missing border.
Width := WorkWidth * 0.75 			;Get the width
Width += ( 2 * Border )				;Alter the width to make up for the missing borders.
Winmove, ahk_group MyBrowsers, XPOS ,, Width				;Move the window
return
User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: Understanding Winmove properly

01 Aug 2021, 22:17

Code: Select all


#left:: ;side by side with  Browsers 
; 75% of prime monitor
SysGet, WorkArea, MonitorWorkArea , 1
WorkWidth := WorkAreaRight - WorkAreaLeft
Width75 := (WorkWidth * 0.75)
Width75 -= ( 5 * Border ) 					;Why 5 borders? should be 2 borders
Border := 10 							;does not go here, the line above is trying to use it. put it 2 lines up.
XPos1 := 0 - Border
XPos2 := ( Width - ( 2 * Border ) ) - Border 		; width75 not width
FullHeight := A_ScreenHeight
FullWidth := WorkWidth
Width25 := WorkWidth * 0.25
Width25 += ( 2 * Border )
Height25 := A_ScreenHeight * 0.25
WinMove, ahk_class ENSingleNoteView,,XPos1, 0 , Width25, FullHeight
WinMove, ahk_group MyBrowsers,,XPos2, 0 , Width75, FullHeight
WinActivate, ahk_class ENSingleNoteView
return

User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: Understanding Winmove properly

01 Aug 2021, 22:23

More issues with your code

Code: Select all



#left:: ;side by side with  Browsers 
; 75% of prime monitor
SysGet, WorkArea, MonitorWorkArea , 1
WorkWidth := WorkAreaRight - WorkAreaLeft
Width75 := (WorkWidth * 0.75)
Width75 -= ( 5 * Border ) 					;Why 5 borders? should be 2 borders
Border := 10 							;does not go here, the line above is trying to use it. put it 2 lines up.
XPos1 := 0 - Border
XPos2 := ( Width - ( 2 * Border ) ) - Border 		; width75 not width ; Correction... This should be width 25
FullHeight := A_ScreenHeight
FullWidth := WorkWidth
Width25 := WorkWidth * 0.25        ;if this is the window on the left, it needs to be set before the right side. 
						   ;You can't use the position of the left window to set the position of the 
						   ;right window if the left window isn't set.
						   
						   
Width25 += ( 2 * Border )					;""   ""
Height25 := A_ScreenHeight * 0.25			;""   ""
WinMove, ahk_class ENSingleNoteView,,XPos1, 0 , Width25, FullHeight
WinMove, ahk_group MyBrowsers,,XPos2, 0 , Width75, FullHeight
WinActivate, ahk_class ENSingleNoteView
return

User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: Understanding Winmove properly

01 Aug 2021, 22:39

Assuming that your winmove code is correct.

Code: Select all



#left:: ;side by side with  Browsers 
; 75% of prime monitor

SysGet, WorkArea, MonitorWorkArea , 1

WorkWidth := WorkAreaRight - WorkAreaLeft
FullWidth := WorkWidth
FullHeight := A_ScreenHeight

Border := 10 

;Win 1 (left)
;***************************
XPos1 := 0 - Border
Width25 := WorkWidth * 0.25     
Width25 += ( 2 * Border )			
WinMove, ahk_class ENSingleNoteView,,XPos1, 0 , Width25, FullHeight

;Win 2 (right)
;***************************
XPos2 := ( Width25 - ( 2 * Border ) ) - Border 	
Width75 := (WorkWidth * 0.75)
Width75 -= ( 5 * Border ) 					
WinMove, ahk_group MyBrowsers,,XPos2, 0 , Width75, FullHeight
							
;***************************
			
WinActivate, ahk_class ENSingleNoteView

return


User avatar
milkygirl90
Posts: 565
Joined: 10 Nov 2020, 21:22

Re: Understanding Winmove properly

01 Aug 2021, 23:53

ah.. thanks for the correction. I'm still having difficulty after using your latest script though:

In addition, it still doesn't work when browser is in maximized mode (i.e. browser doesn't get resized but evernote does)
image.png
(818.59 KiB) Downloaded 103 times
User avatar
Hellbent
Posts: 2102
Joined: 23 Sep 2017, 13:34

Re: Understanding Winmove properly

02 Aug 2021, 11:06

milkygirl90 wrote:
01 Aug 2021, 23:53
ah.. thanks for the correction. I'm still having difficulty after using your latest script though:
I don't know why you have this gap unless you have the wrong size for the border. (I had thought that it was about 5px but you changed it to 10px)
try changing the value of "Border" to 5

*EDIT*
I noticed that the last code I had posted still used your edit ( 5 * Border )

Try this:

Code: Select all



#left:: ;side by side with  Browsers 
; 75% of prime monitor

SysGet, WorkArea, MonitorWorkArea , 1

WorkWidth := WorkAreaRight - WorkAreaLeft
FullWidth := WorkWidth
FullHeight := A_ScreenHeight

Border := 10 

;Win 1 (left)
;***************************
XPos1 := 0 - Border
Width25 := WorkWidth * 0.25     
Width25 += ( 2 * Border )			
WinMove, ahk_class ENSingleNoteView,,XPos1, 0 , Width25, FullHeight

;Win 2 (right)
;***************************
XPos2 := ( Width25 - ( 2 * Border ) ) - Border 	
Width75 := (WorkWidth * 0.75)
Width75 += ( 2 * Border ) 					
WinMove, ahk_group MyBrowsers,,XPos2, 0 , Width75, FullHeight
							
;***************************
			
WinActivate, ahk_class ENSingleNoteView

return


20210802120032.png
(11.85 KiB) Downloaded 72 times
As for the bottom gap. Just add the border to the height.

Code: Select all

FullHeight := A_ScreenHeight + Border
milkygirl90 wrote:
01 Aug 2021, 23:53
In addition, it still doesn't work when browser is in maximized mode (i.e. browser doesn't get resized but evernote does)
Never had a reason to move windows the way you are so I don't know all the in's and out's that would come from doing it a few times, but you can probably use something like WinRestore to take the window of maximized and then try moving it.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: inseption86, mikeyww and 152 guests