Jump to content

to _GUICtrlListView_Create or to GUICtrlCreateListView


Recommended Posts

..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

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

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
Link to comment
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.

Edited by exodius
Link to comment
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.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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

  • Recently Browsing   0 members

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