Sign in to follow this  
Followers 0
AustrianOak

need help with crashing of script

30 posts in this topic

#include <GuiConstantsEx.au3>
#include <GuiEdit.au3>
#include <WindowsConstants.au3>
#include <GUIMenu.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>

Dim $hInput_GUI[6], $Input[6], $wProcsOld[6], $InputMenu[6]

Global $lastdragIP = -1
Global Enum $idOpen = 1000, $idSave, $idInfo

$GUI = GUICreate("Test", 300, 300)

$button5 = GUICtrlCreateButton("", 100, 200, 40, 25)
GUICtrlSetState(-1, $GUI_DEFBUTTON)

GUISetState()

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


While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $button5
            If $lastdragIP < 5 Then
                $lastdragIP += 1
                createNextdragIP($lastdragIP)
            EndIf
        Case $msg = $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
    EndSelect
WEnd

Func createNextdragIP($nw)
$start = WinGetPos($GUI)
$hInput_GUI[$nw] = GUICreate("", 120, 22, $start[0]+30, $start[1]+200, $WS_POPUP, $WS_EX_TOOLWINDOW)
$Input[$nw] = GUICtrlCreateEdit("", 0, 0, 120, 22, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN))


$hMenu = _GUICtrlMenu_CreatePopup()
$InputMenu[$nw] = $hMenu
_GUICtrlMenu_AddMenuItem($hMenu, "Delete", $idOpen)

$wProcsOld[$nw] = _WinAPI_SetWindowLong(GUICtrlGetHandle($Input[$nw]), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))
GUISetState()
WinSetOnTop($hInput_GUI[$nw], "", 1)
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 $idOpen
                            GUICtrlDelete($Input[$i])
                    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

whenever i right click and delete each edit sometimes the script crashes? should i be deleting the edits another way??

Share this post


Link to post
Share on other sites



I have modified your script and I can't get an error but I don't know if I would have got an error befor!

When you delete an edit you need to change the chain of functions called by WinProc which is what I have tried to do. Maybe it fixes tyor problem.

#include <GuiConstantsEx.au3>
#include <GuiEdit.au3>
#include <WindowsConstants.au3>
#include <GUIMenu.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>

Dim $hInput_GUI[6], $Input[6], $wProcsOld[6], $InputMenu[6]

Global $lastdragIP = -1
Global Enum $idOpen = 1000, $idSave, $idInfo

$GUI = GUICreate("Test", 300, 300)

$button5 = GUICtrlCreateButton("", 100, 200, 40, 25)
GUICtrlSetState(-1, $GUI_DEFBUTTON)

GUISetState()

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


While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $GUI_EVENT_CLOSE
            Exit
        Case $Msg = $button5
            If $lastdragIP < 5 Then
                $lastdragIP += 1
                createNextdragIP($lastdragIP)
            EndIf
        Case $Msg = $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
    EndSelect
WEnd

Func createNextdragIP($nw)
    $start = WinGetPos($GUI)
    $hInput_GUI[$nw] = GUICreate("", 120, 22, $start[0] + 30, $start[1] + 200, $WS_POPUP, $WS_EX_TOOLWINDOW)
    $Input[$nw] = GUICtrlCreateEdit("", 0, 0, 120, 22, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN))


    $hMenu = _GUICtrlMenu_CreatePopup()
    $InputMenu[$nw] = $hMenu
    _GUICtrlMenu_AddMenuItem($hMenu, "Delete", $idOpen)

    $wProcsOld[$nw] = _WinAPI_SetWindowLong(GUICtrlGetHandle($Input[$nw]), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))
    GUISetState()
    WinSetOnTop($hInput_GUI[$nw], "", 1)
EndFunc  ;==>createNextdragIP

Func _WindowProc($hWnd, $Msg, $wParam, $lParam)
    Local $wProcOld
    For $i = 0 To $lastdragIP;<----------not Ubound $Input
        If GUICtrlGetHandle($Input[$i]) = $hWnd Then
            $wProcOld = $wProcsOld[$i]
            Switch $Msg
                Case $WM_CONTEXTMENU
                    _GUICtrlMenu_TrackPopupMenu($InputMenu[$i], $wParam)
                    Return 0
                Case $WM_COMMAND
                    Switch $wParam
                        Case $idOpen
                            
                            If $i > 0 Then
                                $wProcsOld[$i] = $wProcsOld[$i - 1]
                                
                                If $i < $lastdragIP Then;we must bypass the proc which is no longer used
                                    $wProcsOld[$i + 1] = $wProcsOld[$i - 1]
                                EndIf
                            EndIf
                            
                            
                            $wProcOld = $wProcsOld[$i]
                            
                            
                            GUICtrlDelete($Input[$i])
                    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

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.

Share this post


Link to post
Share on other sites

martin:

on your code it crashes as well. to get the crash error im seeing make sure you have clicked the button 6 times (to open six edits) and then delete one of them. it should crash if you do this.

Share this post


Link to post
Share on other sites

martin:

on your code it crashes as well. to get the crash error im seeing make sure you have clicked the button 6 times (to open six edits) and then delete one of them. it should crash if you do this.

I tried a fgew times but I can't make it crash.

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.

Share this post


Link to post
Share on other sites

@martin

Wouldn't it be easier to loop from the last to the first? something like

(pseudocode)

for $x = ubound to 0 step -1
I'm not sure. My logic was that if one edit is deleted then the winproc for that one is no longer relevant so it should not be called after the one created later, instead the one after should call the one for the winproc before if that makes 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.

Share this post


Link to post
Share on other sites

well im running beta 3.2.11.5 and my stable release is 3.2.8.1. could this be the problem?

Share this post


Link to post
Share on other sites

bump

Share this post


Link to post
Share on other sites

bump

Share this post


Link to post
Share on other sites

Rather than bumping the thread... update to the current release that all of us use and see if the issue still arises... I doubt anyone is going to downgrade their versions to find bugs that may be version related.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

upgraded to 3.2.13.9 and here's my updated code, its only one line different. i changed it from GUICtrlDelete to GUIDelete so it would delete the whole window instead of just the picture. the problem is when i go to create another one i get this error saying subscript used with non array variable.

#include <GuiConstantsEx.au3>
#include <GuiEdit.au3>
#include <WindowsConstants.au3>
#include <GUIMenu.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>

Dim $hInput_GUI[6], $Input[6], $wProcsOld[6], $InputMenu[6]

Global $lastdragIP = -1
Global Enum $idOpen = 1000, $idSave, $idInfo

$GUI = GUICreate("Test", 300, 300)

$button5 = GUICtrlCreateButton("", 100, 200, 40, 25)
GUICtrlSetState(-1, $GUI_DEFBUTTON)

GUISetState()

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


While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $GUI_EVENT_CLOSE
            Exit
        Case $Msg = $button5
            If $lastdragIP < 5 Then
                $lastdragIP += 1
                createNextdragIP($lastdragIP)
            EndIf
        Case $Msg = $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
    EndSelect
WEnd

Func createNextdragIP($nw)
    $start = WinGetPos($GUI)
    $hInput_GUI[$nw] = GUICreate("", 120, 22, $start[0] + 30, $start[1] + 200, $WS_POPUP, $WS_EX_TOOLWINDOW)
    $Input[$nw] = GUICtrlCreateEdit("", 0, 0, 120, 22, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN))


    $hMenu = _GUICtrlMenu_CreatePopup()
    $InputMenu[$nw] = $hMenu
    _GUICtrlMenu_AddMenuItem($hMenu, "Delete", $idOpen)

    $wProcsOld[$nw] = _WinAPI_SetWindowLong(GUICtrlGetHandle($Input[$nw]), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))
    GUISetState()
    WinSetOnTop($hInput_GUI[$nw], "", 1)
EndFunc ;==>createNextdragIP

Func _WindowProc($hWnd, $Msg, $wParam, $lParam)
    Local $wProcOld
    For $i = 0 To $lastdragIP;<----------not Ubound $Input
        If GUICtrlGetHandle($Input[$i]) = $hWnd Then
            $wProcOld = $wProcsOld[$i]
            Switch $Msg
                Case $WM_CONTEXTMENU
                    _GUICtrlMenu_TrackPopupMenu($InputMenu[$i], $wParam)
                    Return 0
                Case $WM_COMMAND
                    Switch $wParam
                        Case $idOpen
                            
                            If $i > 0 Then
                                $wProcsOld[$i] = $wProcsOld[$i - 1]
                                
                                If $i < $lastdragIP Then;we must bypass the proc which is no longer used
                                    $wProcsOld[$i + 1] = $wProcsOld[$i - 1]
                                EndIf
                            EndIf
                            
                            
                            $wProcOld = $wProcsOld[$i]
                            
                            
                            GUIDelete($hInput_GUI[$i])
                    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
Edited by AustrianOak

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

1) I get no error but If I create a edit, I delete it, then, if I re-create a new edit I cant delete it...

2) I want to know how u use WindowProc

Edited by oMBra

Share this post


Link to post
Share on other sites

what version u got

Share this post


Link to post
Share on other sites

3.2.12.1 and Beta

Share this post


Link to post
Share on other sites

what version beta??

Share this post


Link to post
Share on other sites

3.2.13.9

Share this post


Link to post
Share on other sites

#include <GuiConstantsEx.au3>
#include <GuiEdit.au3>
#include <WindowsConstants.au3>
#include <GUIMenu.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>

Dim $hInput_GUI[6], $Input[6], $wProcsOld[6], $InputMenu[6]

Global $lastdragIP = -1
Global Enum $idOpen = 1000, $idSave, $idInfo

$GUI = GUICreate("Test", 300, 300)

$button5 = GUICtrlCreateButton("", 100, 200, 40, 25)
GUICtrlSetState(-1, $GUI_DEFBUTTON)

GUISetState()

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


While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $GUI_EVENT_CLOSE
            Exit
        Case $Msg = $button5
            If $lastdragIP < 5 Then
                $lastdragIP += 1
                createNextdragIP($lastdragIP)
            EndIf
        Case $Msg = $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
    EndSelect
WEnd

Func createNextdragIP($nw)
    $start = WinGetPos($GUI)
    $hInput_GUI[$nw] = GUICreate("", 120, 22, $start[0] + 30, $start[1] + 200, $WS_POPUP, $WS_EX_TOOLWINDOW)
    $Input[$nw] = GUICtrlCreateEdit("", 0, 0, 120, 22, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN))


    $hMenu = _GUICtrlMenu_CreatePopup()
    $InputMenu[$nw] = $hMenu
    _GUICtrlMenu_AddMenuItem($hMenu, "Delete", $idOpen)

    $wProcsOld[$nw] = _WinAPI_SetWindowLong(GUICtrlGetHandle($Input[$nw]), $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))
    GUISetState()
    WinSetOnTop($hInput_GUI[$nw], "", 1)
EndFunc ;==>createNextdragIP

Func _WindowProc($hWnd, $Msg, $wParam, $lParam)
    Local $wProcOld
    For $i = 0 To $lastdragIP;<----------not Ubound $Input
        If GUICtrlGetHandle($Input[$i]) = $hWnd Then
            $wProcOld = $wProcsOld[$i]
            Switch $Msg
                Case $WM_CONTEXTMENU
                    _GUICtrlMenu_TrackPopupMenu($InputMenu[$i], $wParam)
                    Return 0
                Case $WM_COMMAND
                    Switch $wParam
                        Case $idOpen
                            
                            If $i > 0 Then
                                $wProcsOld[$i] = $wProcsOld[$i - 1]
                                
                                If $i < $lastdragIP Then;we must bypass the proc which is no longer used
                                    $wProcsOld[$i + 1] = $wProcsOld[$i - 1]
                                EndIf
                            EndIf
                            
                            
                            $wProcOld = $wProcsOld[$i]
                            
                            
                            GUIDelete($hInput_GUI[$i])
                    EndSwitch
            EndSwitch
            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

The problem is somewhere in the deletion part of the code in the WindowProc(). It crashes for me after I delete an edit or a few. It's totally random sometimes.

Share this post


Link to post
Share on other sites

bump

Share this post


Link to post
Share on other sites

bump

Share this post


Link to post
Share on other sites

When you say crash is this hard crash or does it crash with an error?

Are you using the full version of SciTE? If not please install it and run the script, showing and then paste the output pane.

Cheers,

Brett

Share this post


Link to post
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
Sign in to follow this  
Followers 0