Jump to content

GUI crashes when using GUIDelete inside WM_NOTIFY


ale1981
 Share

Go to solution Solved by Melba23,

Recommended Posts

I might be doing this wrong but this seems to crash the GUI, what I want is to click the button, select something from the list view with a double click which populates the input box and delete's the GUI?

#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Test", 400, 400)
$btn = GUICtrlCreateButton( "", 150, 50, 75, 20 )
$cInput = GUICtrlCreateInput( "", 10, 50, 100, 20 )

GUISetState()
GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" )

Global $idListview

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btn
            listpackers()
    EndSwitch
WEnd

Func listPackers()

    Global $packersGUI = GUICreate( "Packers List", 300, 300, -1, -1, $WS_SYSMENU )
    $idListview = GUICtrlCreateListView( "", 2, 2, 294, 268 )
    GUISetState( @SW_SHOW )

    Local $packerList[2][2] = [[1, "Name1"],[2, "Name2"]]

    ; Add columns
    _GUICtrlListView_AddColumn( $idListview, "Packer ID", 75 )
    _GUICtrlListView_AddColumn( $idListview, "Packer Name", 150 )

    _GUICtrlListView_SetItemCount( $idListview, 3 )
    _GUICtrlListView_AddArray( $idListview, $packerList )
    _GUICtrlListView_DeleteItem( $idListview, 0 )

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()

EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $tBuffer, $tBuffer2

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $iIDFrom
        Case $idListview
            Switch $iCode
                Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    GUICtrlSetData( $cInput, _GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index")) )
                    GUIDelete( $packersGUI )
                    Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc
Link to comment
Share on other sites

  • Moderators
  • Solution

ale1981,

Try doing it this way: ;)

#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Test", 400, 400)
$btn = GUICtrlCreateButton( "", 150, 50, 75, 20 )
$cInput = GUICtrlCreateInput( "", 10, 50, 100, 20 )

GUISetState()
GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" )

Global $idListview, $packersGUI, $cDummy

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btn
            listpackers()
    EndSwitch
WEnd

Func listPackers()

    $packersGUI = GUICreate( "Packers List", 300, 300, -1, -1, $WS_SYSMENU )
    $idListview = GUICtrlCreateListView( "", 2, 2, 294, 268 )

    $cDummy = GUICtrlCreateDummy() ; Create dummy control

    GUISetState( @SW_SHOW )

    Local $packerList[2][2] = [[1, "Name1"],[2, "Name2"]]

    ; Add columns
    _GUICtrlListView_AddColumn( $idListview, "Packer ID", 75 )
    _GUICtrlListView_AddColumn( $idListview, "Packer Name", 150 )

    _GUICtrlListView_SetItemCount( $idListview, 3 )
    _GUICtrlListView_AddArray( $idListview, $packerList )
    _GUICtrlListView_DeleteItem( $idListview, 0 )

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $cDummy ; When dummy fired
                $iIndex = GUICtrlRead($cDummy) ; Read index
                GUICtrlSetData( $cInput, _GUICtrlListView_GetItemText($idListview, $iIndex) ) ; Get data into input
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete($packersGUI)

EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $tBuffer, $tBuffer2

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $iIDFrom
        Case $idListview
            Switch $iCode
                Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    GUICtrlSendToDummy($cDummy, DllStructGetData($tInfo, "Index")) ; Fire dummy and set index value
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc
Now you only delete the GUI in the main script and not in the message handler. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

×
×
  • Create New...