Tsukihime Posted April 21, 2011 Share Posted April 21, 2011 (edited) The application I am writing scripts for allow you to close sub-windows and open them. Each sub-window contains a number of controls. I set all of the handles at the beginning of the script and then loop a GUI. However when I close the sub-window and create another, some scripts no longer work, in particular the ones that rely on handles. I checked the handles and it appears that they have changed, but they shouldn't be a problem because I run my script from scratch everytime, so it would retrieve the handles at that point. Basically, when I create a new sub-window, the scripts don't work properly, but when I run the code again, it works fine. Has anyone encountered something like this? Edited April 21, 2011 by Tsukihime Link to comment Share on other sites More sharing options...
Tsukihime Posted April 21, 2011 Author Share Posted April 21, 2011 (edited) Alright, I added a function that assigns the handles everytime I run my script and it seems to be doing the trick. Definitely seems to be handle changing issue. But is this the only solution? It seems rather inelegant. Edited April 21, 2011 by Tsukihime Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 21, 2011 Share Posted April 21, 2011 Handles remain the same for as long as the object exists (window, control, etc.), but they will be different every time that object is created. So a window always has a unique handle when it gets created. If the window is only hidden and then restored it will still have the same handle, but if it is deleted and re-created it will have a new handle. That's all by design. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Tsukihime Posted April 21, 2011 Author Share Posted April 21, 2011 So the only solution I have when it comes to destroying objects and creating new ones is to assign all the necessary handles again? Link to comment Share on other sites More sharing options...
KaFu Posted April 21, 2011 Share Posted April 21, 2011 Either that or created the window just once and toggle the visibility (show / hide) as needed. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 21, 2011 Share Posted April 21, 2011 If your own code is creating the object, you catch the handle at that point and don't have to derive it from anything: #include <GuiConstantsEx.au3> #include <GuiEdit.au3> Global $hGUI, $idButton, $hButton, $hEdit = 0 $hGUI = GUICreate("My GUI", 300, 200) ; $hGUI contains the window handle $idButton = GUICtrlCreateButton("TEST", 100, 50, 100, 30) ; $idButton is the control ID (integer) $hButton = GUICtrlGetHandle($idButton) ; $hButton is the button handle GUISetState() ; Run the GUI until the dialog is closed While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $idButton If IsHWnd($hEdit) Then _GUICtrlEdit_Destroy($hEdit) $hEdit = _GUICtrlEdit_Create($hGUI, "", 10, 100, 280, 90) ; $hEdit is the edit control handle ControlSetText($hGUI, "", $hEdit, "$hGUI = " & $hGUI & @CRLF & _ "$idButton = " & $idButton & @CRLF & _ "$hButton = " & $hButton & @CRLF & _ "$hEdit = " & $hEdit) EndSwitch WEnd Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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