Jump to content
Sign in to follow this  
freat_cuvox

Func _Middle Doesn't Work As Intended

Recommended Posts

freat_cuvox

Hi,

I'm trying to create a script to simply center any active window on screen when I press a shortcut. I found this "Func _Middle" (below) in the forums but it doesn't center it perfectly horizontally (always a little to right) and it doesn't take into consideration the size of the taskbar, so it stays too low. How can I change these values to center it perfectly in the screen taking into account the taskbar? I have played around with the values and looked for alternatives in the forums but found nothing. I also want it run at start up and hide the tray icon but I'll figure those things out later. :-)

HotKeySet("+1", "_Middle")
Func _Middle($win, $txt)
   $size = WinGetClientSize("", "")
   Local $y = (@DesktopHeight / 2) - ($size[1] / 2)
   Local $x = (@DesktopWidth / 2) - ($size[0] / 2)
   Return WinMove("", "", $x, $y)
EndFunc  ;==>_Middle
While 1
   Sleep (100)
WEnd

Share this post


Link to post
Share on other sites
kaisies

Look into winapi getsystemmetrics. 

 

Don't remember which one specifically as I'm on mobile, but it'd pretty obvious from what I remember 

Share this post


Link to post
Share on other sites
Malkey

Try this.

HotKeySet("+1", "_Middle") ; Press Shift and "1" keys, or, the "!" key to centre (Oxford dictionary) the active window.
HotKeySet("{ESC}", "Terminate") ; Perss Esc key to exit.

While 1
   Sleep (100)
WEnd


Func _Middle()
   ;$size = WinGetClientSize("", "")
   $size = WinGetPos("", "")
   Local $y = (@DesktopHeight / 2) - ($size[3] / 2)
   Local $x = (@DesktopWidth / 2) - ($size[2] / 2)
   WinMove("", "", $x, $y)
EndFunc  ;==>_Middle

Func Terminate()
    Exit
EndFunc   ;==>Terminate

 

Share this post


Link to post
Share on other sites
freat_cuvox

That did it! Thanks Malkey!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×