maniootek

GUIRegisterMsg(WM_NOTIFY) cause _ArrayDisplay() fail

3 posts in this topic

#1 ·  Posted (edited)

This happens to me again. GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") cause _ArrayDisplay pop up freeze without any data displayed.

Code example:

#include <WindowsConstants.au3> ;$WM_NOTIFY
#include <GUIConstantsEx.au3> ;$GUI_RUNDEFMSG
#include <GuiListView.au3> ;$tagNMHDR
#include <Array.au3>

GUICreate("")
$idListview = GUICtrlCreateListView("col1", 5, 5)
GUICtrlCreateListViewItem("item", $idListview)
GUICtrlCreateListViewItem("item", $idListview)

Local $aArray[0]
for $i=0 to 10
    _ArrayAdd($aArray, $i)
Next

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

; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $idOK
            ExitLoop
    EndSwitch
WEnd


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = GUICtrlGetHandle($idListview)
    If Not IsHWnd($hWndListView) Then $hWndListView = GUICtrlGetHandle($hWndListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode

                Case -3 ;$NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)

                    $index = DllStructGetData($tInfo, "Index")
                    $subitemNR = DllStructGetData($tInfo, "SubItem")

                    If $index <> -1 Then
                        ;msgbox(0,0,$index & $subitemNR)
                        _ArrayDisplay($aArray)
                    EndIf

            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

result

_arraydisplay.PNG

any idea what could be wrong? is it a bug?

Edited by Melba23
Amended title

Share this post


Link to post
Share on other sites



maniootek,

Most certainly not a bug and entirely due to your code. The Help file is quite clear:

Warning: blocking of running user functions which executes window messages with commands such as "MsgBox()" can lead to unexpected behavior, the return to the system should be as fast as possible !!!

_ArrayDisplay is a blocking function - so the crash is quite expected.

You need to set a flag in the handler and then action it in your idle loop - like this:

#include <WindowsConstants.au3> ;$WM_NOTIFY
#include <GUIConstantsEx.au3> ;$GUI_RUNDEFMSG
#include <GuiListView.au3> ;$tagNMHDR
#include <Array.au3>

Global $fActivated = False

GUICreate("")
$idListview = GUICtrlCreateListView("col1", 5, 5)
GUICtrlCreateListViewItem("item", $idListview)
GUICtrlCreateListViewItem("item", $idListview)

Local $aArray[0]
for $i=0 to 10
    _ArrayAdd($aArray, $i)
Next

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

; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $idOK
            ExitLoop
    EndSwitch

    If $fActivated Then
        $fActivated = False
        ;msgbox(0,0,$index & $subitemNR)
        _ArrayDisplay($aArray)
    EndIf

WEnd


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = GUICtrlGetHandle($idListview)
    If Not IsHWnd($hWndListView) Then $hWndListView = GUICtrlGetHandle($hWndListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode

                Case -3 ;$NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)

                    $index = DllStructGetData($tInfo, "Index")
                    $subitemNR = DllStructGetData($tInfo, "SubItem")

                    If $index <> -1 Then
                        $fActivated = True
                    EndIf

            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

M23

2 people like this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Thank you, it works now.

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