MyEarth Posted January 9, 2015 Posted January 9, 2015 (edited) From the snippet: https://www.autoitscript.com/wiki/Snippets_(_GUI_)#Center_Window_on_Screen #include <GUIConstantsEx.au3> Global Const $GUI = GUICreate("Test Window",300 ,300 ,100 ,100) GUISetState(@SW_SHOWNORMAL) Sleep(2000) _Middle($GUI, "Test Window") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func _Middle(Const $win, Const $txt) Local Const $size = WinGetClientSize($win, $txt) Local Const $y = (@DesktopHeight / 2) - ($size[1] / 2) Local Const $x = (@DesktopWidth / 2) - ($size[0] / 2) Return WinMove($win, $txt, $x, $y) EndFunc ;==>_Middle Pratically i want to add the the _Middle function the ability to resize AND put on the center. Using two different WinMove is easy but the result does not suit to me. I'd like to do the operation with only one WinMove. Thank you Edited January 9, 2015 by MyEarth
Exit Posted January 9, 2015 Posted January 9, 2015 And we should spoon-feed you ? App: Au3toCmd UDF: _SingleScript()
MyEarth Posted January 9, 2015 Author Posted January 9, 2015 (edited) Bad moon today? Yes spoon-feed me with your superior knowledge mr.programmer... Again, i have changed that function with 2 WinMove, resize the window and use _Middle, and i like to know if is possible to only one WinMove or is necessary to resize first. Edited January 9, 2015 by MyEarth
AZJIO Posted January 9, 2015 Posted January 9, 2015 Show your example with two functions. I will change it. My other projects or all
Exit Posted January 9, 2015 Posted January 9, 2015 I have changed that function with 2 WinMove, resize the window and use _MiddleSo, would you like to share those efforts ? App: Au3toCmd UDF: _SingleScript()
MyEarth Posted January 9, 2015 Author Posted January 9, 2015 I'll post it since it is so required, dunno why but ok. expandcollapse popup#include <GUIConstantsEx.au3> Global $GUI = GUICreate("Test Window", 100, 100, 100, 100) GUISetState(@SW_SHOW) Sleep(2000) _Middle2($GUI, "Test Window", 300, 300) ; just for test if is correct centered like the original one <<<<<<<<<<<<<<<<<<<<< $size = WinGetPos($GUI) ConsoleWrite("Active window stats (x,y,width,height):" & $size[0] & " " & $size[1] & " " & $size[2] & " " & $size[3] & @CRLF) Sleep(1000) _Middle($GUI, "Test Window") $size = WinGetPos($GUI) ConsoleWrite("Active window stats (x,y,width,height):" & $size[0] & " " & $size[1] & " " & $size[2] & " " & $size[3] & @CRLF) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func _Middle2($win, $txt, $width, $height) Local $aWin = WinGetPos($win) WinMove($win, $txt, $aWin[0], $aWin[1], $width, $height) ; first winmove Local $size = WinGetClientSize($win, $txt) Local $y = (@DesktopHeight / 2) - ($size[1] / 2) Local $x = (@DesktopWidth / 2) - ($size[0] / 2) Return WinMove($win, $txt, $x, $y) ; second winmove EndFunc ;==>_Middle Func _Middle(Const $win, Const $txt) Local Const $size = WinGetClientSize($win, $txt) Local Const $y = (@DesktopHeight / 2) - ($size[1] / 2) Local Const $x = (@DesktopWidth / 2) - ($size[0] / 2) Return WinMove($win, $txt, $x, $y) ; second winmove EndFunc ;==>_Middle
jdelaney Posted January 9, 2015 Posted January 9, 2015 (edited) Looks fine to me...switched out one function call...and no need for _Middle anymore: #include <GUIConstantsEx.au3> Global $GUI = GUICreate("Test Window", 100, 100, 100, 100) GUISetState(@SW_SHOW) Sleep(2000) _Middle2($GUI, "Test Window", 300, 300) ; just for test if is correct centered like the original one <<<<<<<<<<<<<<<<<<<<< $size = WinGetPos($GUI) ConsoleWrite("Active window stats (x,y,width,height):" & $size[0] & " " & $size[1] & " " & $size[2] & " " & $size[3] & @CRLF) Sleep(1000) _Middle2($GUI, "Test Window", 100, 100) $size = WinGetPos($GUI) ConsoleWrite("Active window stats (x,y,width,height):" & $size[0] & " " & $size[1] & " " & $size[2] & " " & $size[3] & @CRLF) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func _Middle2($win, $txt, $width, $height) Local $aWin = WinGetPos($win) WinMove($win, $txt, $aWin[0], $aWin[1], $width, $height) ; first winmove Local $size = WinGetClientSize($win, $txt) Local $y = (@DesktopHeight / 2) - ($size[1] / 2) Local $x = (@DesktopWidth / 2) - ($size[0] / 2) Return WinMove($win, $txt, $x, $y) ; second winmove EndFunc ;==>_Middle Edit: small improvement: expandcollapse popup#include <GUIConstantsEx.au3> Global $GUI = GUICreate("Test Window", 100, 100, 100, 100) GUISetState(@SW_SHOW) Sleep(2000) _Middle2($GUI, "Test Window", 300, 300) ; just for test if is correct centered like the original one <<<<<<<<<<<<<<<<<<<<< $size = WinGetPos($GUI) ConsoleWrite("Active window stats (x,y,width,height):" & $size[0] & " " & $size[1] & " " & $size[2] & " " & $size[3] & @CRLF) Sleep(1000) _Middle2($GUI, "Test Window",800) $size = WinGetPos($GUI) ConsoleWrite("Active window stats (x,y,width,height):" & $size[0] & " " & $size[1] & " " & $size[2] & " " & $size[3] & @CRLF) Sleep(1000) _Middle2($GUI, "Test Window",Default,1000) $size = WinGetPos($GUI) ConsoleWrite("Active window stats (x,y,width,height):" & $size[0] & " " & $size[1] & " " & $size[2] & " " & $size[3] & @CRLF) Sleep(1000) ; change back _Middle2($GUI, "Test Window", 100, 100) $size = WinGetPos($GUI) ConsoleWrite("Active window stats (x,y,width,height):" & $size[0] & " " & $size[1] & " " & $size[2] & " " & $size[3] & @CRLF) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func _Middle2($win, $txt, $width=-1, $height=-1) If $width >= 0 Or $height >= 0 Then Local $aWin = WinGetPos($win) If $width < 0 Then $width = $aWin[2] If $height < 0 Then $height = $aWin[3] WinMove($win, $txt, $aWin[0], $aWin[1], $width, $height) ; first winmove EndIf Local $size = WinGetClientSize($win, $txt) Local $y = (@DesktopHeight / 2) - ($size[1] / 2) Local $x = (@DesktopWidth / 2) - ($size[0] / 2) Return WinMove($win, $txt, $x, $y) ; second winmove EndFunc ;==>_Middle Edited January 9, 2015 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
MyEarth Posted January 9, 2015 Author Posted January 9, 2015 jdelaney i know it work but the question is always the same: Is possible to use only one WinMove for resizing AND center instead of two, one for resize and one for center?
Solution jdelaney Posted January 9, 2015 Solution Posted January 9, 2015 (edited) Oh, that's what you wanted? sure...just needs more calcs before hand. Give it a go, we can correct your problems. Had a bug in my script, so providing your needed func: Func _Middle2($win, $txt, $width=Default, $height=Default) Local $size = WinGetClientSize($win, $txt) If Not ($width = Default) Then $size[0] = $width If Not ($height = Default) Then $size[1] = $height Local $x = (@DesktopWidth / 2) - ($size[0]/ 2) Local $y = (@DesktopHeight / 2) - ($size[1]/ 2) Return WinMove($win, $txt, $x, $y, $size[0], $size[1]) ; second winmove EndFunc ;==>_Middle Edited January 9, 2015 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now