Sign in to follow this  
Followers 0
argumentum

to _GUICtrlListView_Create or to GUICtrlCreateListView

5 posts in this topic

#1 ·  Posted (edited)

..if I use _GUICtrlListView_Create I cant get "WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)" to work ! help

here is an example of what I'm going though

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>


$Form1 = GUICreate("Form1", 273, 203, 302, 218)
$ListView1 = GUICtrlCreateListView("", 8, 40, 250, 150)
;~ $ListView1 = _GUICtrlListView_Create($Form1,"", 8, 40, 250, 150)
$Button1 = GUICtrlCreateButton("Delete selected", 8, 8, 251, 25, 0)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY,"WM_NOTIFY")

$hContextMenu = GUICtrlCreateContextMenu($ListView1)
$Open_MenuItem = GUICtrlCreateMenuItem("Open", $hContextMenu)
$Del_MenuItem1 = GUICtrlCreateMenuItem("Delete", $hContextMenu)

_GUICtrlListView_InsertColumn($ListView1, 0, "Document",200)
_GUICtrlListView_AddItem($ListView1, "Data", 0)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Del_MenuItem1
            ConsoleWrite("$Del_MenuItem1 - " & _GUICtrlListView_DeleteItem($ListView1,_GUICtrlListView_GetSelectedIndices($ListView1)) &@CRLF)

    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
;~  ConsoleWrite($hWnd &"|"& $Msg &"|"& $wParam &"|"& $lParam &@CRLF)
    Local $hWnd_ListView, $tNMHDR, $hWndFrom, $iCode
    
    $hWnd_ListView = $ListView1
    If Not IsHWnd($hWnd_ListView) Then $hWnd_ListView = GUICtrlGetHandle($ListView1)
    
;~     $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    Switch $hWndFrom
        Case $hWnd_ListView
            Switch $iCode
                Case $NM_RCLICK
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                    Local $iItem = DllStructGetData($tInfo, "Item")
                    
                    If $iItem = -1 Then
                        GUICtrlSetState($Open_MenuItem, $GUI_DISABLE)
                        GUICtrlSetState($Del_MenuItem1, $GUI_DISABLE)
                    Else
                        GUICtrlSetState($Open_MenuItem, $GUI_ENABLE)
                        GUICtrlSetState($Del_MenuItem1, $GUI_ENABLE)
                    EndIf
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc
Edited by argumentum

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If you're going to use WM_Notify, you need to use GUIRegisterMsg to activate it. Your code otherwise worked perfectly fine:

*Edit - I fixed your delete function too. Just use the GuiCtrlCreateListView function.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>


$Form1 = GUICreate("Form1", 273, 203, 302, 218)
$ListView1 = GUICtrlCreateListView("", 8, 40, 250, 150)
$Button1 = GUICtrlCreateButton("Delete selected", 8, 8, 251, 25, 0)

$hContextMenu = GUICtrlCreateContextMenu($ListView1)
$Open_MenuItem = GUICtrlCreateMenuItem("Open", $hContextMenu)
$Del_MenuItem1 = GUICtrlCreateMenuItem("Delete", $hContextMenu)

_GUICtrlListView_InsertColumn($ListView1, 0, "Document",200)
_GUICtrlListView_AddItem($ListView1, "Data", 0)

;Register WM_NOTIFY  events
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE 
            Exit
        Case $Del_MenuItem1
            $varSelected = _GUICtrlListView_GetSelectedIndices($ListView1, True)
            For $x = 1 to $varSelected[0]
                ConsoleWrite("$Del_MenuItem1 - Index:" & $varSelected[$x] & " Result:" & _GUICtrlListView_DeleteItem(GUICtrlGetHandle ($ListView1), $varSelected[$x]) &@CRLF)
            Next

    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $hWnd_ListView, $tNMHDR, $hWndFrom, $iCode
   
    $hWnd_ListView = $ListView1
    If Not IsHWnd($hWnd_ListView) Then $hWnd_ListView = GUICtrlGetHandle($ListView1)
   
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
   
    Switch $hWndFrom
        Case $hWnd_ListView
            Switch $iCode
                Case $NM_RCLICK
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                    Local $iItem = DllStructGetData($tInfo, "Item")
                   
                    If $iItem = -1 Then
                        GUICtrlSetState($Open_MenuItem, $GUI_DISABLE)
                        GUICtrlSetState($Del_MenuItem1, $GUI_DISABLE)
                    Else
                        GUICtrlSetState($Open_MenuItem, $GUI_ENABLE)
                        GUICtrlSetState($Del_MenuItem1, $GUI_ENABLE)
                    EndIf
            EndSwitch
    EndSwitch
   
    Return $GUI_RUNDEFMSG
EndFunc
Edited by exodius

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I modified my original post to account for that. That was simply a problem with how you were trying to delete the item.

*Edit - Which subsequently has nothing to do with WM_Notify, which is just disabling or enabling your context menu items.

Edited by exodius

Share this post


Link to post
Share on other sites

I modified my original post to account for that. That was simply a problem with how you were trying to delete the item.

*Edit - Which subsequently has nothing to do with WM_Notify, which is just disabling or enabling your context menu items.

..so many thanks exodius, thank you.

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