Mingre Posted April 10, 2013 Share Posted April 10, 2013 Hello! How do I enable contextmenu for listview without the need to disable WM_NOTIFY()? Here's my working code expandcollapse popup#include #include #include #include #include Opt('GUIOnEventMode', 1) Opt('MustDeclareVars', 1) Opt('TrayIconDebug',1) $Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work Global $contextmenu, $iFileItem, $lsTime, $lsPrice Global $hListView, $StatusBar, $iIndex = -1, $iSubIndex = -1 Global Const $laComputers = StringSplit('G01|G02|G03|G04|G05|G06|G07|G08|G09|G10|G11|G12|G13', '|', 1) ; flag = 1, entire delimiter string is needed to mark the split HotKeySet('{ESC}', 'fexit') _Main() Func _Main() Local $hImage, $GUI, $lsINIfile, $cMenu1, $cLVCM ; Create GUI $GUI = GUICreate('Title', 400, 300) GUICtrlSetDefColor(0xFFFFFF, Default) $hListView = GUICtrlCreateListView("", 2, 2, 394, 268) GUICtrlSetStyle(Default, BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS), BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_FLATSB)) GUICtrlSetCursor(Default, 0) GUICtrlSetBkColor(Default, 0x000000) ;$cLVCM = GUICtrlCreateContextMenu($hListView) ;$iFileItem = GUICtrlCreateMenuItem("Open", $cLVCM) $StatusBar = _GUICtrlStatusBar_Create($GUI, -1, "") _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_SUBITEMIMAGES) $hImage = _GUIImageList_Create(10, 10) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x000000, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16)) _GUICtrlListView_SetImageList($hListView, $hImage, 1) ; Add columns _GUICtrlListView_AddColumn($hListView, "Comp", 50) _GUICtrlListView_AddColumn($hListView, "Notes", 150) ; Add items For $tNumber = 1 To $laComputers[0] Step +1 _GUICtrlListView_AddItem($hListView, $laComputers[$tNumber]) Next GUISetState() $hListView = GUICtrlGetHandle($hListView) ; get the handle for use in the notify events GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 Sleep(1000) WEnd EndFunc ;==>_Main Func fExit() Exit EndFunc Func ListView_Click() Local $aHit, $sInputNotes, $sReadNotes $aHit = _GUICtrlListView_SubItemHitTest($hListView) If ($aHit[0] <> -1) And (($aHit[0] <> $iIndex) Or ($aHit[1] <> $iSubIndex)) Then _GUICtrlStatusBar_SetText($StatusBar, @TAB & StringFormat("HitTest Item: %d, SubItem: %d", $aHit[0], $aHit[1])) $iIndex = $aHit[0] $iSubIndex = $aHit[1] EndIf If $iSubIndex = 1 Then $sReadNotes = _GUICtrlListView_GetItemText($hListView, $aHit[0], $aHit[1]) $sInputNotes = InputBox('Edit notes for ' & _GUICtrlListView_GetItemText($hListView, $aHit[0]), '', $sReadNotes) If @error = 1 Then ; 1 = The Cancel button was pushed. Else _GUICtrlListView_SetItemText($hListView, $aHit[0], $sInputNotes, $aHit[1]) EndIf EndIf EndFunc ;==>ListView_Click Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK ; A column was clicked $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) _DebugPrint("$LVN_COLUMNCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode & @LF & _ "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @LF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _ "-->Param:" & @TAB & DllStructGetData($tInfo, "Param")) ; No return value Case $LVN_KEYDOWN ; A key has been pressed $tInfo = DllStructCreate($tagNMLVKEYDOWN, $ilParam) _DebugPrint("$LVN_KEYDOWN" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode & @LF & _ "-->VKey:" & @TAB & DllStructGetData($tInfo, "VKey") & @LF & _ "-->Flags:" & @TAB & DllStructGetData($tInfo, "Flags")) ; No return value Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) _DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode & @LF & _ "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _ "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _ "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags")) ListView_Click() ; No return value Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) _DebugPrint("$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode & @LF & _ "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _ "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _ "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags")) ; No return value Case $NM_KILLFOCUS ; The control has lost the input focus _DebugPrint("$NM_KILLFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode) ; No return value Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the right mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) _DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode & @LF & _ "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _ "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _ "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags")) ;Return 1 ; not to allow the default processing Return 0 ; allow the default processing Case $NM_RDBLCLK ; Sent by a list-view control when the user double-clicks an item with the right mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) _DebugPrint("$NM_RDBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode & @LF & _ "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _ "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _ "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags")) ; No return value Case $NM_RETURN ; The control has the input focus and that the user has pressed the ENTER key _DebugPrint("$NM_RETURN" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode) ; No return value Case $NM_SETFOCUS ; The control has received the input focus _DebugPrint("$NM_SETFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode) ; No return value EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _DebugPrint($s_text, $line = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @LF & _ "+======================================================" & @LF & _ "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _ "+======================================================" & @LF) EndFunc ;==>_DebugPrint Thanks! Link to comment Share on other sites More sharing options...
Mingre Posted April 10, 2013 Author Share Posted April 10, 2013 Hello. Found out that I just need to remove "Case $NM_RCLICK". Thanks everyone. Link to comment Share on other sites More sharing options...
autovroom Posted September 28, 2013 Share Posted September 28, 2013 AWESOME!!!! it ate my brain for sometime, thanks Mingre!!! 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