argumentum Posted May 13, 2009 Share Posted May 13, 2009 (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 expandcollapse popup#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 May 13, 2009 by argumentum Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
exodius Posted May 13, 2009 Share Posted May 13, 2009 (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. expandcollapse popup#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 May 13, 2009 by exodius Link to comment Share on other sites More sharing options...
argumentum Posted May 13, 2009 Author Share Posted May 13, 2009 If you're going to use WM_Notify, you need to use GUIRegisterMsg to activate it. Your code otherwise worked perfectly fine:it does not work for it does not delete the entry =/ Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
exodius Posted May 13, 2009 Share Posted May 13, 2009 (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 May 13, 2009 by exodius Link to comment Share on other sites More sharing options...
argumentum Posted May 13, 2009 Author Share Posted May 13, 2009 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now