Jump to content

Recommended Posts

Posted

was looking into adding a function that auto checks items on select
using the example Here: it works 


but when I'm launching the GUI from a inside a function the GUIRegisterMsg wont kick in
what i am missing here ?
Thanks

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GuiListView.au3>

Global $listview
_example()

Func _example()
    Local $msg
    GUICreate("_example", 400, 300, -1, -1)
    Local $listview = GUICtrlCreateListView("Product ID|Category|Last Update", 2, 2, 394, 250)
    _GUICtrlListView_SetExtendedListViewStyle($listview, BitOR($LVS_EX_BORDERSELECT, $LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES))
    GUISetState()

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    GUICtrlCreateListViewItem("1|2|3", $listview)
    GUICtrlCreateListViewItem("4|5|6", $listview)
    GUICtrlCreateListViewItem("7|8|9", $listview)

    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
    GUIDelete()
EndFunc   ;==>_example

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    If $iIDFrom = $listview Then
        Switch $iCode
            Case $NM_CLICK
                Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                If @error Then Return $GUI_RUNDEFMSG
                Local $Item = DllStructGetData($tInfo, "Index")
                If @error Or $Item = -1 Then Return $GUI_RUNDEFMSG

                Local $tTest = DllStructCreate($tagLVHITTESTINFO)
                DllStructSetData($tTest, "X", DllStructGetData($tInfo, "X"))
                DllStructSetData($tTest, "Y", DllStructGetData($tInfo, "Y"))
                Local $iRet = GUICtrlSendMsg($iIDFrom, $LVM_HITTEST, 0, DllStructGetPtr($tTest))
                If @error Or $iRet = -1 Then Return $GUI_RUNDEFMSG
                Switch DllStructGetData($tTest, "Flags")
                    Case $LVHT_ONITEMICON, $LVHT_ONITEMLABEL, $LVHT_ONITEM
                        If _GUICtrlListView_GetItemChecked($listview, $Item) = False Then
                            _GUICtrlListView_SetItemChecked($listview, $Item, 1)
                        Else
                            _GUICtrlListView_SetItemChecked($listview, $Item, 0)
                        EndIf
                    Case $LVHT_ONITEMSTATEICON ;on checkbox
                EndSwitch
        EndSwitch
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Posted (edited)

There is nothing missing. There is 1 Local to much. The 2. in line 12, after removing it the ControlID of the LV is assigned to Global $ListView (line 6) as needed.

Edited by AutoBert
  • 4 weeks later...
Posted (edited)
On 28/03/2016 at 8:42 AM, AutoBert said:

There is nothing missing. There is 1 Local to much. The 2. in line 12, after removing it the ControlID of the LV is assigned to Global $ListView (line 6) as needed.

Yep, as AutoBert says, you are declaring a Global variable $listview, but this is not actually assigned to the listview. it is just a blank global variable. You go on to create your GUI with a listview within the function as a Local variable (i.e. only used within the function). Hence why you are not getting any messages from the WM_NOTIFY function. 

Remove the "Local" and it will work as expected:

$listview = GUICtrlCreateListView("Product ID|Category|Last Update", 2, 2, 394, 250)
Edited by mpower

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...