Jump to content

deletion of moveable gui


Recommended Posts

the code below if ran creates three pictures that if clicked on spawn moveable guis. my problem however is if you click each one once and then have 3 moveable guis, if you delete the first one and then try to create another one on the first picture it doesn't move at all.

#include <GuiConstantsEx.au3>
#include <GuiEdit.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>
#include <GUIMENU.au3>

Global $merlin = @SystemDir & "\oobe\images\merlin.gif" 
Global $ahInput[2][7]
Dim $Icon[3]

$gui = GUICreate("Hypertrophy's GUI", 400, 400)

$Icon[0] = GUICtrlCreatePic($merlin, 24, 60, 24, 22)
$Icon[1] = GUICtrlCreatePic($merlin, 69, 60, 24, 22)
$Icon[2] = GUICtrlCreatePic($merlin, 114, 60, 24, 22)

GUISetState()

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[0]
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Icon[0],$Icon[1],$Icon[2]
            CreateDragIP()
        Case $ahInput[1][1] To $ahInput[$ahInput[0][0]][1]
                If $msg[0] = 0 Then ContinueLoop

                Local $aMouse_Pos = MouseGetPos()
                Local $aCursorInfo = GUIGetCursorInfo($msg[1]), $aCurrent_Mouse_Pos, $aInputGUI_Pos

                $aInputGUI_Pos = WinGetPos($msg[1])
                If Not IsArray($aInputGUI_Pos) Then ContinueLoop

                While IsArray($aCursorInfo) And $aCursorInfo[2] = 1
                    $aCursorInfo = GUIGetCursorInfo($msg[1])
                    $aCurrent_Mouse_Pos = MouseGetPos()

                    WinMove($msg[1], "", _
                            $aInputGUI_Pos[0] - $aMouse_Pos[0] + $aCurrent_Mouse_Pos[0], _
                            $aInputGUI_Pos[1] - $aMouse_Pos[1] + $aCurrent_Mouse_Pos[1])

                    Sleep(10)
                WEnd
    EndSwitch
        
; loop for handling dragip events
    
    For $i = 1 To $ahInput[0][0]
        If IsArray($msg) Then
            Switch $msg[0]
                Case $ahInput[$i][3]; This is the "Delete" item message
                    DeleteDragIP($msg[0])
                    ExitLoop
            EndSwitch
        EndIf
    Next

WEnd

Func CreateDragIP()
    Local $aMainGUI_Pos = WinGetPos($Gui)
    $ahInput[0][0] += 1
    ReDim $ahInput[$ahInput[0][0] + 1][4]
    
    If $msg[0] = $Icon[0] Then
        $ipos = ControlGetPos($Gui, "", $Icon[0])
    ElseIf $msg[0] = $Icon[1] Then
        $ipos = ControlGetPos($Gui, "", $Icon[1])
    ElseIf $msg[0] = $Icon[2] Then
        $ipos = ControlGetPos($Gui, "", $Icon[2])
    EndIf
    
    $ahInput[$ahInput[0][0]][0] = GUICreate("", 24, 24, $aMainGUI_Pos[0] + $ipos[0] + 5, $aMainGUI_Pos[1] + $ipos[1] + 50, _
        $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_LAYERED))
        
    If $msg[0] = $Icon[0] Then
        $ahInput[$ahInput[0][0]][1] = GUICtrlCreatePic($merlin, 0, 0, 24, 22, -1)
    ElseIf $msg[0] = $Icon[1] Then
        $ahInput[$ahInput[0][0]][1] = GUICtrlCreatePic($merlin, 0, 0, 24, 22, -1)
    ElseIf $msg[0] = $Icon[2] Then
        $ahInput[$ahInput[0][0]][1] = GUICtrlCreatePic($merlin, 0, 0, 24, 22, -1)
    EndIf
    
    $ahInput[$ahInput[0][0]][2] = GUICtrlCreateContextMenu($ahInput[$ahInput[0][0]][1])
    $ahInput[$ahInput[0][0]][3] = GUICtrlCreateMenuItem("&Delete", $ahInput[$ahInput[0][0]][2])

    GUISetState(@SW_SHOW, $ahInput[$ahInput[0][0]][0])

    WinSetOnTop($ahInput[$ahInput[0][0]][0], "", 1)
EndFunc
    
Func DeleteDragIP($iCtrlID)
    Local $aTmpArr[2][9]

    For $i = 1 To $ahInput[0][0]
        If $ahInput[$i][3] = $iCtrlID Then
            GUIDelete($ahInput[$i][0])
        Else
            $aTmpArr[0][0] += 1
            ReDim $aTmpArr[$aTmpArr[0][0] + 1][9]

            $aTmpArr[$aTmpArr[0][0]][0] = $ahInput[$i][0]
            $aTmpArr[$aTmpArr[0][0]][1] = $ahInput[$i][1]
            $aTmpArr[$aTmpArr[0][0]][2] = $ahInput[$i][2]
            $aTmpArr[$aTmpArr[0][0]][3] = $ahInput[$i][3]
        EndIf
Next
$ahInput = $aTmpArr
EndFunc;==>DeleteDragIP
Edited by Hypertrophy
Link to comment
Share on other sites

I think you need to rethink the way you are doing this. You have a Switch structure where you check for the case of IDs of controls but that won't work because the ids of controls in different windows can be the same.

So you need to either use the handles for the controls or you need to check which window gave the message first, and then check the id in that window to see where the message came from.

Does that make sense?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Hmm. sorta.

What do you mean the ids of controls in different windows can be the same? sorry i dont understand what you meant by that.

and I may have misunderstood but I dont think I can use the handles for the controls because there may be an unlimited number of windows.

Link to comment
Share on other sites

bump

Take this function for example.

Func DeleteDragIP($iCtrlID)
    Local $aTmpArr[2][9]

    For $i = 1 To $ahInput[0][0]
        If $ahInput[$i][3] = $iCtrlID Then
            GUIDelete($ahInput[$i][0])
        Else
            $aTmpArr[0][0] += 1
            ReDim $aTmpArr[$aTmpArr[0][0] + 1][9]

            $aTmpArr[$aTmpArr[0][0]][0] = $ahInput[$i][0]
            $aTmpArr[$aTmpArr[0][0]][1] = $ahInput[$i][1]
            $aTmpArr[$aTmpArr[0][0]][2] = $ahInput[$i][2]
            $aTmpArr[$aTmpArr[0][0]][3] = $ahInput[$i][3]
        EndIf
Next
$ahInput = $aTmpArr
EndFunc;==>DeleteDragIP

and in particular these lines

If $ahInput[$i][3] = $iCtrlID Then
             GUIDelete($ahInput[$i][0])

I think the problem you are having is because you think an id is unique. Say you create a gui and add a control which has id 15. Then you delete the gui. Then you create a new gui and add a control and you will find that that now has the id of 15. So now you have 15 appearing in two places in your array but you assume that the first one you find is the correct one, but it could be from the gui that was previously deleted.

I think something like this might help. When you delete a gui set all the elements for that gui to zero. When you crete a new gui first see if there is an empty slot for it in your array because a gui was deleted. If no empty slot then grow the array as you do now and add the details.

If you add a line to your function as I've shown below, then I think that if yoiu create new guis and delete one then create another you will see an id is used again and this is what defeats your script.

Func CreateDragIP()
    Local $aMainGUI_Pos = WinGetPos($Gui)
    $ahInput[0][0] += 1
    ReDim $ahInput[$ahInput[0][0] + 1][4]

    If $msg[0] = $Icon[0] Then
        $ipos = ControlGetPos($Gui, "", $Icon[0])
    ElseIf $msg[0] = $Icon[1] Then
        $ipos = ControlGetPos($Gui, "", $Icon[1])
    ElseIf $msg[0] = $Icon[2] Then
        $ipos = ControlGetPos($Gui, "", $Icon[2])
    EndIf

    $ahInput[$ahInput[0][0]][0] = GUICreate("", 24, 24, $aMainGUI_Pos[0] + $ipos[0] + 5, $aMainGUI_Pos[1] + $ipos[1] + 50, _
        $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_LAYERED))

    If $msg[0] = $Icon[0] Then
        $ahInput[$ahInput[0][0]][1] = GUICtrlCreatePic($merlin, 0, 0, 24, 22, -1)

    ElseIf $msg[0] = $Icon[1] Then
        $ahInput[$ahInput[0][0]][1] = GUICtrlCreatePic($merlin, 0, 0, 24, 22, -1)
    ElseIf $msg[0] = $Icon[2] Then
        $ahInput[$ahInput[0][0]][1] = GUICtrlCreatePic($merlin, 0, 0, 24, 22, -1)
    EndIf
    ConsoleWrite("next ip ID = " & $ahInput[$ahInput[0][0]][1] & @CRLF);<------------------------------------debug line added
    $ahInput[$ahInput[0][0]][2] = GUICtrlCreateContextMenu($ahInput[$ahInput[0][0]][1])
    $ahInput[$ahInput[0][0]][3] = GUICtrlCreateMenuItem("&Delete", $ahInput[$ahInput[0][0]][2])

    GUISetState(@SW_SHOW, $ahInput[$ahInput[0][0]][0])

    WinSetOnTop($ahInput[$ahInput[0][0]][0], "", 1)
EndFunc
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I have added that line and I don't want to be flamed by you but I truly do not understand the significance of what you are getting at. I had help building part of this code and I wasn't good with arrays and obviously still am not.. :)

If you don't understand something I said why should I flame you?

One good reason you might not have understood what I was saying is that a lot of it was nonsense. I hadn't read the script properly and seen how the array was handled when a gui is deleted.

The problem is still to do with the fact that once a gui is deleted the ID used by a control is then reuesed in a newly created gui.

So the problem is in this line

Case $ahInput[1][1] To $ahInput[$ahInput[0][0]][1]

because you consider ID values from the one in the first set to one in the last set. But the last set can have an ID of lower value than the sets in between. So the solution is something like this

#include <GuiConstantsEx.au3>
#include <GuiEdit.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>
#include <GUIMENU.au3>

Global $merlin = @SystemDir & "\oobe\images\merlin.gif"
Global $ahInput[2][4]
$ahInput[0][0] = 0
Dim $Icon[3]

$gui = GUICreate("Hypertrophy's GUI", 400, 400)

$Icon[0] = GUICtrlCreatePic($merlin, 24, 60, 24, 22)
$Icon[1] = GUICtrlCreatePic($merlin, 69, 60, 24, 22)
$Icon[2] = GUICtrlCreatePic($merlin, 114, 60, 24, 22)

ConsoleWrite("icon id's = " & $Icon[0] & ', ' & $Icon[1] & ', ' & $Icon[2] & @CRLF)
GUISetState()

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[0]
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Icon[0], $Icon[1], $Icon[2]
            CreateDragIP()
        Case Else
            If $msg[0] = 0 Then ContinueLoop

            For $n = 1 To $ahInput[0][0]
                If $msg[0] = $ahInput[$n][1] Then


                    Local $aMouse_Pos = MouseGetPos()
                    Local $aCursorInfo = GUIGetCursorInfo($msg[1]), $aCurrent_Mouse_Pos, $aInputGUI_Pos

                    $aInputGUI_Pos = WinGetPos($msg[1])
                    If Not IsArray($aInputGUI_Pos) Then ContinueLoop

                    While IsArray($aCursorInfo) And $aCursorInfo[2] = 1
                        $aCursorInfo = GUIGetCursorInfo($msg[1])
                        $aCurrent_Mouse_Pos = MouseGetPos()

                        WinMove($msg[1], "", _
                                $aInputGUI_Pos[0] - $aMouse_Pos[0] + $aCurrent_Mouse_Pos[0], _
                                $aInputGUI_Pos[1] - $aMouse_Pos[1] + $aCurrent_Mouse_Pos[1])

                        Sleep(10)
                    WEnd
                EndIf
            Next
    EndSwitch


    ; loop for handling dragip events

    For $i = 1 To $ahInput[0][0]
        If IsArray($msg) Then
            Switch $msg[0]
                Case $ahInput[$i][3]; This is the "Delete" item message
                    DeleteDragIP($msg[0])
                    ExitLoop
            EndSwitch
        EndIf
    Next

WEnd

Func CreateDragIP()
    Local $aMainGUI_Pos = WinGetPos($gui)
    $ahInput[0][0] += 1
    ReDim $ahInput[$ahInput[0][0] + 1][4]

    If $msg[0] = $Icon[0] Then
        $ipos = ControlGetPos($gui, "", $Icon[0])
    ElseIf $msg[0] = $Icon[1] Then
        $ipos = ControlGetPos($gui, "", $Icon[1])
    ElseIf $msg[0] = $Icon[2] Then
        $ipos = ControlGetPos($gui, "", $Icon[2])
    EndIf

    $ahInput[$ahInput[0][0]][0] = GUICreate("", 24, 24, $aMainGUI_Pos[0] + $ipos[0] + 5, $aMainGUI_Pos[1] + $ipos[1] + 50, _
            $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_LAYERED))

    If $msg[0] = $Icon[0] Then
        $ahInput[$ahInput[0][0]][1] = GUICtrlCreatePic($merlin, 0, 0, 24, 22, -1)

    ElseIf $msg[0] = $Icon[1] Then
        $ahInput[$ahInput[0][0]][1] = GUICtrlCreatePic($merlin, 0, 0, 24, 22, -1)
    ElseIf $msg[0] = $Icon[2] Then
        $ahInput[$ahInput[0][0]][1] = GUICtrlCreatePic($merlin, 0, 0, 24, 22, -1)
    EndIf
    ConsoleWrite("next ip ID = " & $ahInput[$ahInput[0][0]][1] & @CRLF)
    $ahInput[$ahInput[0][0]][2] = GUICtrlCreateContextMenu($ahInput[$ahInput[0][0]][1])
    $ahInput[$ahInput[0][0]][3] = GUICtrlCreateMenuItem("&Delete", $ahInput[$ahInput[0][0]][2])

    GUISetState(@SW_SHOW, $ahInput[$ahInput[0][0]][0])

    WinSetOnTop($ahInput[$ahInput[0][0]][0], "", 1)
EndFunc   ;==>CreateDragIP

Func DeleteDragIP($iCtrlID)
    Local $aTmpArr[2][9]

    For $i = 1 To $ahInput[0][0]
        If $ahInput[$i][3] = $iCtrlID Then
            GUIDelete($ahInput[$i][0])
        Else
            $aTmpArr[0][0] += 1
            ReDim $aTmpArr[$aTmpArr[0][0] + 1][9]

            $aTmpArr[$aTmpArr[0][0]][0] = $ahInput[$i][0]
            $aTmpArr[$aTmpArr[0][0]][1] = $ahInput[$i][1]
            $aTmpArr[$aTmpArr[0][0]][2] = $ahInput[$i][2]
            $aTmpArr[$aTmpArr[0][0]][3] = $ahInput[$i][3]
        EndIf
    Next
    $ahInput = $aTmpArr
EndFunc   ;==>DeleteDragIP

EDIT:rewrote the post after realizing I had misunderstood the script.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...