Jump to content

deletion of movable edits


Recommended Posts

hi, plz this not all my code most of it is but i have taken some from other users that i give credit to just trying figure why script crashes when i right click to delete an edit and try to make more and delete and it crashes. also the max edits that can be created it 6 i made it that way. but when i create one and then delete that one i can only create 5 more and it keeps decrementing.

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

Global Enum $idDelete = 1000, $idSave, $idInfo
Global $lastdragIP = -1
Dim $hInput_GUI[50], $Input[50], $wProcsOld[6], $InputMenu[6]

$gui = GUICreate("", 400, 400)

$button = GUICtrlCreateButton("", 50, 50, 50, 20)
GUISetState()

$wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam")
$wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($Input), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button
                If $lastdragIP < 5 Then
                    $lastdragIP += 1
                    createNextdragIP($lastdragIP)
                EndIf
        Case $GUI_EVENT_PRIMARYDOWN 
            
            $aMouse_Pos = MouseGetPos()
            $sel = -1
            For $n = 0 To $lastdragIP
                GUISwitch($hInput_GUI[$n])
                $aCursorInfo = GUIGetCursorInfo()

                If Not IsArray($aCursorInfo) Then ContinueLoop
                If $aCursorInfo[4] = $Input[$n] Then
                    $sel = $n
                    ExitLoop
                EndIf

            Next
            If $sel = -1 Then ContinueLoop
            $aInputGUI_Pos = WinGetPos($hInput_GUI[$sel])
            While IsArray($aCursorInfo) And $aCursorInfo[2] = 1
                $aCursorInfo = GUIGetCursorInfo()
                $aCurrent_Mouse_Pos = MouseGetPos()

                WinMove($hInput_GUI[$sel], "", _
                        $aInputGUI_Pos[0] - $aMouse_Pos[0] + $aCurrent_Mouse_Pos[0], _
                        $aInputGUI_Pos[1] - $aMouse_Pos[1] + $aCurrent_Mouse_Pos[1])
            WEnd
    EndSwitch
WEnd
DllCallbackFree($wProcHandle)

Func createNextdragIP($nw)
    $start = WinGetPos($gui)
    $hInput_GUI[$nw] = GUICreate("No. " & $nw + 1, 120, 22, 300 + 25 * $nw, 300 + 25 * $nw, BitOR($WS_POPUP, $WS_SIZEBOX), $WS_EX_TOOLWINDOW)
    $Input[$nw] = GUICtrlCreateEdit("", 0, 0, 120, 22, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN))
    GUICtrlSetResizing(-1, $GUI_DOCKAUTO)

    $hMenu = _GUICtrlMenu_CreatePopup()
    $InputMenu[$nw] = $hMenu
    
    _GUICtrlMenu_AddMenuItem($hMenu, "Delete", $idDelete)
    _GUICtrlMenu_AddMenuItem($hMenu, "Save", $idSave)
    _GUICtrlMenu_AddMenuItem($hMenu, "Info", $idInfo)
    $wProcsOld[$nw] = _WinAPI_SetWindowLong(GUICtrlGetHandle($Input[$nw]), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))
    GUISetState()
EndFunc  ;==>createNextdragIP


Func _WindowProc($hWnd, $Msg, $wParam, $lParam)
    Local $wProcOld
    For $i = 0 To UBound($Input)-1
        If GUICtrlGetHandle($Input[$i]) = $hWnd Then
            Switch $Msg
                Case $WM_CONTEXTMENU
                    _GUICtrlMenu_TrackPopupMenu($InputMenu[$i], $wParam)
                    Return 0
                Case $WM_COMMAND
                    Switch $wParam
                        Case $idDelete
                            GUIDelete($hInput_GUI)
                        Case $idSave
                            ConsoleWrite("-> Save" & @LF)
                        Case $idInfo
                            ConsoleWrite("-> Info" & @LF)
                    EndSwitch
            EndSwitch
            $wProcOld = $wProcsOld[$i]
            ExitLoop
        EndIf
    Next

    Local $aRet = DllCall("user32.dll", "int", "CallWindowProc", "ptr", $wProcOld, _
    "hwnd", $hWnd, "uint", $Msg, "wparam", $wParam, "lparam", $lParam)
    Return $aRet[0]
EndFunc
Link to comment
Share on other sites

  • 4 weeks later...

i want the script above to not crash when i delete the edits. if there is something you can point out or change so it will work fine (meaning i can create 6 edits and delete them whenever however i want) then that would be very helpful.

Link to comment
Share on other sites

bump

Try this

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

Global $idDelete[6], $idSave[6], $idInfo[6]
For $i = 0 To 5
    $idDelete[$i] = 1000 + $i
    $idSave[$i] = 1010 + $i
    $idInfo[$i] = 1020 + $i
Next
Global $wProcOld
Global $lastdragIP = -1
Dim $hInput_GUI[50], $Input[50], $wProcsOld[6], $InputMenu[6], $hMenu[6], $idDelete[6], $idSave[6], $ifInfo[6]
Dim $button
$gui = GUICreate("", 400, 400)

$button = GUICtrlCreateButton("", 50, 50, 50, 20)
GUISetState()

$wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam")

$toDelete = 0
$iW = -1
Global $totCreated = 0
While 1
    $msg = GUIGetMsg(1)
    $iW = -1
    For $i = 0 To 5
        If $msg[1] = $hInput_GUI[$i] Then
            $iW = $i
            ExitLoop
        EndIf
    Next
    If $iW >= 0 Or $msg[1] = $gui Then
        Switch $msg[0]
            Case $GUI_EVENT_CLOSE
                Exit
            Case $button
                If $totCreated < 6 Then
                    For $i = 0 To 5
                        If $hInput_GUI[$i] = 0 Then
                            createNextdragIP($i)
                            $totCreated += 1
                            ExitLoop
                        EndIf
                    Next
                Else
                    MsgBox(262144, "MAX Reached", "You are omnly allowed 6 Edits!")
                EndIf
            Case $GUI_EVENT_PRIMARYDOWN


        EndSwitch
    EndIf


WEnd
DllCallbackFree($wProcHandle)

Func createNextdragIP($nw)

    $start = WinGetPos($gui)
    $hInput_GUI[$nw] = GUICreate("No. " & $nw + 1, 120, 22, 300 + 25 * $nw, 300 + 25 * $nw, BitOR($WS_POPUP, $WS_SIZEBOX), $WS_EX_TOOLWINDOW)
    $Input[$nw] = GUICtrlCreateEdit("", 0, 0, 120, 22, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN))
    GUICtrlSetResizing(-1, $GUI_DOCKAUTO)

    $hMenu = _GUICtrlMenu_CreatePopup()
    $InputMenu[$nw] = $hMenu

    _GUICtrlMenu_AddMenuItem($hMenu, "Delete", $idDelete[$nw])
    _GUICtrlMenu_AddMenuItem($hMenu, "Save", $idSave[$nw])
    _GUICtrlMenu_AddMenuItem($hMenu, "Info", $idInfo[$nw])
    ConsoleWrite("90" & @CRLF)
    GUISetState()

    $wProcsOld[$nw] = _WinAPI_SetWindowLong(GUICtrlGetHandle($Input[$nw]), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))
EndFunc  ;==>createNextdragIP


Func _WindowProc($hWnd, $msg, $wParam, $lParam)
Local $wProcOld

    For $i = 0 To UBound($Input) - 1
        If GUICtrlGetHandle($Input[$i]) = $hWnd Then
            Switch $msg
                Case $WM_CONTEXTMENU
                    _GUICtrlMenu_TrackPopupMenu($InputMenu[$i], $wParam)
                    Return 0
                Case $WM_COMMAND
                    Switch $wParam
                        Case $idDelete[$i]
                            ConsoleWrite("delete" & @CRLF)
                            GUIDelete($hInput_GUI[$i])
                            $hInput_GUI[$i] = 0
                            $totCreated -= 1
                        Case $idSave[$i]
                            ConsoleWrite("-> Save" & @LF)
                        Case $idInfo[$i]
                            ConsoleWrite("-> Info" & @LF)
                    EndSwitch
            EndSwitch
            $wProcOld = $wProcsOld[$i]
            ExitLoop
        EndIf
    Next

    Local $aRet = DllCall("user32.dll", "int", "CallWindowProc", "ptr", $wProcOld, _
            "hwnd", $hWnd, "uint", $msg, "wparam", $wParam, "lparam", $lParam)
    Return $aRet[0]
EndFunc  ;==>_WindowProc

This looks familiar.

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

Thank you martin! :) The only problem left is that if I delete the edits in any order except descending (6th,5th, then 4th,etc) autoit crashes. Do you know why?

If I run the posted code and create and delete edits and create them again and delete in any order, or just delete some then create again then delete them all then create 1 or 2 then delete then create untill I'm totally bored with it then I don't see any crash.

If you can tell me how to make it crash I'll try it.

EDIT: I've tried with production version 3.3.0.0 and Beta version 3.3.1.0.

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

Here's how it crashes for me. I create 6 edits and then delete the second (or third, etc) one and it crashes saying Autoit has encountered a problem and needs to close, etc etc. I am running 3.2.8.1 with beta 3.2.11.5. Please don't tell me update because my script is wayyy to long. If you want I can give you both autoit installers so you can see if you can identify the problem with the version i have. thanks for your help

3.2.8.1: http://rapidshare.com/files/239873879/auto...-setup.exe.html

3.2.11.5: http://rapidshare.com/files/239876383/auto...-setup.exe.html

Edited by coder09
Link to comment
Share on other sites

If I hadn't tried updating already than I would have. But when I tried it on my 2000 line script there was way to much i had to change/take out/errors

There is no problem with the script I posted using 3.3.0.0.

I think updating to overcome a problem is a good time to update, and I expect it won't be so painful as you fear.

Of course there might be something wrong with what I posted that you can get away with in 3.3.0.0, so it's still possible the script can be made to work without updating. I think the delete Case is supect in my code. Try adding Retun 0 at the end of the delete Case in _WInproc like this

Case $idDelete[$i]
                             ConsoleWrite("delete" & @CRLF)
                             GUIDelete($hInput_GUI[$i])
                             $hInput_GUI[$i] = 0
                             $totCreated -= 1
                             return 0:<--------------
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

There is no problem with the script I posted using 3.3.0.0.

I think updating to overcome a problem is a good time to update, and I expect it won't be so painful as you fear.

Of course there might be something wrong with what I posted that you can get away with in 3.3.0.0, so it's still possible the script can be made to work without updating. I think the delete Case is supect in my code. Try adding Retun 0 at the end of the delete Case in _WInproc like this

Case $idDelete[$i]
                             ConsoleWrite("delete" & @CRLF)
                             GUIDelete($hInput_GUI[$i])
                             $hInput_GUI[$i] = 0
                             $totCreated -= 1
                             return 0:<--------------
i just downloaded beta 3.3.1.0 will it make a difference b/w your version which is 3.3.0.0?
Link to comment
Share on other sites

i just downloaded beta 3.3.1.0 will it make a difference b/w your version which is 3.3.0.0?

No.

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

Thanks so much for all the help martin. I'm in the process of updating my code and its going good. I was just wondering if you knew how to re-implement my moving the notes code. You took it out in response to my first post and I put it back in but it didn't work... :D

Link to comment
Share on other sites

bump

I don't know what the "notes code" is.

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...