Jump to content

Handles are changing?


Recommended Posts

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 by Tsukihime
Link to comment
Share on other sites

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 by Tsukihime
Link to comment
Share on other sites

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.

:unsure:

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

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

:unsure:

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...