qwert Posted May 3, 2008 Share Posted May 3, 2008 Would anyone happen to know of a UDF or code snippet that, upon exiting a GUI, will note the current window position -- and then provide those coordinates to the same script the next time it is run? I would think this is a common need and that it has been solved already. However, if I'm unable to locate existing code, my plan is to use WinGetPos in an exit function as a basis for writing a simple text file -- and then (at startup) have the script read the file and position accordingly. Any suggestions of a better method will be appreciated. Thanks in advance. Link to comment Share on other sites More sharing options...
Generator Posted May 3, 2008 Share Posted May 3, 2008 Would anyone happen to know of a UDF or code snippet that, upon exiting a GUI, will note the current window position -- and then provide those coordinates to the same script the next time it is run?I would think this is a common need and that it has been solved already. However, if I'm unable to locate existing code, my plan is to use WinGetPos in an exit function as a basis for writing a simple text file -- and then (at startup) have the script read the file and position accordingly. Any suggestions of a better method will be appreciated.Thanks in advance.Technically there aren't any snippets or UDF for this, your only approach would either be writing a txt file and reading it or write a registry value and read it again later. Link to comment Share on other sites More sharing options...
qwert Posted May 3, 2008 Author Share Posted May 3, 2008 Technically there aren't any snippets or UDF for this, your only approach would either be writing a txt file and reading it or write a registry value and read it again later.Thanks for weighing in on this. I'm not to keen on writing to the registry, so I guess the text file is my best bet. Link to comment Share on other sites More sharing options...
MrCreatoR Posted May 3, 2008 Share Posted May 3, 2008 Here is an example... expandcollapse popup#include <GuiConstants.au3> Global $ConfigFile = StringTrimRight(@ScriptFullPath, 3) & "ini" $GUI = GUICreate("GUI Restore Position", 300, 200, -1, -1, BitOr($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX)) _GUIRestorePositions($GUI, $ConfigFile) GUISetState(@SW_SHOW, $GUI) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _GUISavePositions($GUI, $ConfigFile) Exit EndSwitch WEnd Func _GUISavePositions($hGUI, $sConfigFile, $sSectName="Window Positions") Local $aGUI_Pos = WinGetPos($hGUI) If @error Then Return 0 IniWrite($sConfigFile, $sSectName, "Left", $aGUI_Pos[0]) IniWrite($sConfigFile, $sSectName, "Top", $aGUI_Pos[1]) IniWrite($sConfigFile, $sSectName, "Width", $aGUI_Pos[2]) IniWrite($sConfigFile, $sSectName, "Height", $aGUI_Pos[3]) Return 1 EndFunc Func _GUIRestorePositions($hGUI, $sConfigFile, $sSectName="Window Positions", $iDefWidth=300, $iDefHeight=200) Local $iGUI_Left = IniRead($sConfigFile, $sSectName, "Left", -1) Local $iGUI_Top = IniRead($sConfigFile, $sSectName, "Top", -1) Local $iGUI_Width = IniRead($sConfigFile, $sSectName, "Width", $iDefWidth) Local $iGUI_Height = IniRead($sConfigFile, $sSectName, "Height", $iDefHeight) If $iGUI_Left = -1 Then $iGUI_Left = (@DesktopWidth / 2) - ($iGUI_Width / 2) If $iGUI_Top = -1 Then $iGUI_Top = (@DesktopHeight / 2) - ($iGUI_Height / 2) Return WinMove($hGUI, "", $iGUI_Left, $iGUI_Top, $iGUI_Width, $iGUI_Height) EndFunc Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
qwert Posted May 3, 2008 Author Share Posted May 3, 2008 Thank you, sir. That's exactly what I was looking for. Now, thanks to you, the technique exists! Link to comment Share on other sites More sharing options...
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