;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction udfWinCenter (strWindowTitle) arrCoord = Arrayize (WinPlaceGet (@NORMAL, strWindowTitle), " ") Return WinPlace ((1000 - arrCoord[2] + arrCoord[0]) / 2, (1000 - arrCoord[3] + arrCoord[1]) / 2, @NORESIZE, @NORESIZE, strWindowTitle) ;.......................................................................................................................................... ; This UDF "udfWinCenter" will center a window on the screen without resizing it. ; ; Window coordinates: "ulx uly lrx lry". ; arrCoord[0] ... ulx ... upper left x. ; arrCoord[1] ... uly ... upper left y. ; arrCoord[2] ... lrx ... lower right x. ; arrCoord[3] ... lry ... lower right y. ; ; Return value: ; @TRUE .... If a window was found to move. ; @FALSE ... If no window were found. ;.......................................................................................................................................... ; Detlev Dalitz.20120423. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ; Test. ; We use a notepad window to demonstrate how it works. hdlPID = RunShell ("notepad.exe", "", "", @NORMAL, @GETPROCID) While WinItemProcId (hdlPID, 0, 0) == "" TimeDelay (1) EndWhile hdlWinId = ItemExtract (1, WinItemProcId (hdlPID, 2, 0), @TAB) SendKeysTo (hdlWinId, "Test for automatically centering a window without changing the size.") TimeDelay (2) WinPlace (800, 50, @NORESIZE, @NORESIZE, hdlWinId) ; Set the window right out of the screen. SendKeysTo (hdlWinId, @CRLF : "Window is moved out of screen.") TimeDelay (2) blnResult = udfWinCenter (hdlWinId) ; Get the window back into the middle of the screen. SendKeysTo (hdlWinId, @CRLF : "Window is centered.") TimeDelay (2) SendKeysTo (hdlWinId, @CRLF : "Window will be closed automatically.") TimeDelay (1) :CANCEL SendKeysTo (hdlWinId, "^a{DEL}") WinClose (hdlWinId) Exit