Code: Select all
Run, "C:\Users\Peter\Scripts\AHK\quicknotes.ahk",,, PID
WinWait, ahk_pid %PID%
WinActivate, ahk_pid %PID%
WinMove, ahk_pid %PID%, , , , 1200, 700
Code: Select all
Run, "C:\Users\Peter\Scripts\AHK\quicknotes.ahk",,, PID
WinWait, ahk_pid %PID%
WinActivate, ahk_pid %PID%
WinMove, ahk_pid %PID%, , , , 1200, 700
Code: Select all
;Take the width of your screen and divide it by 2
;Then subtract half of the width of the window
x := (A_ScreenWidth//2) - (Window_Width//2)
;Then do the same for the height
y := (A_ScreenHeight//2) - (Window_Height//2)
;Lastly, show you window at x and y
WinMove,Some Window, x%x% y%y%
Code: Select all
Run, "C:\Users\Peter\Scripts\AHK\quicknotes.ahk",,, PID
WinWait, ahk_pid %PID%
WinActivate, ahk_pid %PID%
WinMove, ahk_pid %PID%, , , , 1200, 700
x := (A_ScreenWidth//2) - (Window_Width//2)
y := (A_ScreenHeight//2) - (Window_Height//2)
WinMove,Some Window, x%x% y%y%
DutchPete wrote:I don't see where to add my laptop's screen dimensions which are 1366x768Code: Select all
Run, "C:\Users\Peter\Scripts\AHK\quicknotes.ahk",,, PID WinWait, ahk_pid %PID% WinActivate, ahk_pid %PID% WinMove, ahk_pid %PID%, , , , 1200, 700 x := (A_ScreenWidth//2) - (Window_Width//2) y := (A_ScreenHeight//2) - (Window_Height//2) WinMove,Some Window, x%x% y%y%
Code: Select all
Run, "C:\Users\Peter\Scripts\AHK\quicknotes.ahk",,, PID
WinWait, ahk_pid %PID%
WinActivate, ahk_pid %PID%
Width:=1200
Height:=700
x_var := (A_ScreenWidth//2) - (Width//2) ;Note "A_ScreenWidth" is a variable that is built into ahk that gets the screen resolution for you, same with "A_ScreenHeight"
y_var := (A_ScreenHeight//2) - (Height//2)
WinMove, ahk_pid %PID%, ,x_var ,y_var ,Width,Height
Code: Select all
WinGetPos, , , w, h, ahk_pid %PID%
x := (A_ScreenWidth - w) // 2
y := (A_ScreenHeight - h) // 2
WinMove, ahk_pid %PID%, , % x, % y
So Swagfag, your code is slightly different from Hellbent's, but when I use it (total code script below), it does not work - the window remains unchanged. Hellbent's solution works.swagfag wrote:Code: Select all
WinGetPos, , , w, h, ahk_pid %PID% x := (A_ScreenWidth - w) // 2 y := (A_ScreenHeight - h) // 2 WinMove, ahk_pid %PID%, , % x, % y
Code: Select all
Run, "C:\Users\Peter\Scripts\AHK\quicknotes.ahk",,, PID
WinWait, ahk_pid %PID%
WinActivate, ahk_pid %PID%
Width:=1200
Height:=700
WinGetPos, , , w, h, ahk_pid %PID%
x := (A_ScreenWidth - w) // 2
y := (A_ScreenHeight - h) // 2
WinMove, ahk_pid %PID%, , % x, % y
if you want to tweak your y position you can just take the result of the y_var and add or subtract from itDutchPete wrote:Hellbent, yes that works fine.
Is there a way to move the window up a few pixels to the height dimension?
Code: Select all
;before y_var was set like this
y_var := (A_ScreenHeight//2) - (Height//2)
;or
y_var := (A_ScreenHeight-Height)//2
;You can adjust it in a few ways
;( 1 )
; adding or subtracting
y_var := (A_ScreenHeight-Height)//2
y_Var += 100 ;adding (setting the window lower on the screen)
y_Var -= 100 ;subtracting (setting the window higher on the screen)
; ( 2)
; Adjusting in the same line as you set y_Var
; ADDING (Moving window lower)
y_var := (A_ScreenHeight-Height)//2 + 100
; SUBTRACTING (Moving window higher)
y_var := (A_ScreenHeight-Height)//2 - 100
Thanks Hellbent, you're a star. I now got it working exactly the way I want. Thanks a lotif you want to tweak your y position you can just take the result of the y_var and add or subtract from it
if you want the y to be the top of the screen and only center the x then you can omit the y:=(blah blah blah),Code: Select all
;before y_var was set like this y_var := (A_ScreenHeight//2) - (Height//2) ;or y_var := (A_ScreenHeight-Height)//2 ;You can adjust it in a few ways ;( 1 ) ; adding or subtracting y_var := (A_ScreenHeight-Height)//2 y_Var += 100 ;adding (setting the window lower on the screen) y_Var -= 100 ;subtracting (setting the window higher on the screen) ; ( 2) ; Adjusting in the same line as you set y_Var ; ADDING (Moving window lower) y_var := (A_ScreenHeight-Height)//2 + 100 ; SUBTRACTING (Moving window higher) y_var := (A_ScreenHeight-Height)//2 - 100
and just say that y:=0
Code: Select all
Run, notepad.exe, , , PID
WinWait, ahk_pid %PID%
WinActivate, ahk_pid %PID%
WinGetPos, , , w, h, ahk_pid %PID%
x := (A_ScreenWidth - w) // 2
y := (A_ScreenHeight - h) // 2
WinMove, ahk_pid %PID%, , % x, % y
Users browsing this forum: filipemb and 289 guests