Stacker Posted June 6, 2016 Share Posted June 6, 2016 Hi all, i need to enable/disable an item($listitem3) on context menu if find a specific value in listview ($idlistview).The item start disable (see code) I use GUIGetMsg() in my code $listtxt = GUICtrlCreateContextMenu($idListView) $listitem1 = GUICtrlCreateMenuItem("Ignore", $idListView) $listitem2 = GUICtrlCreateMenuItem("Remove Ignore", $idListView) $listitem3 = GUICtrlCreateMenuItem("Provide", $idListView) GUICtrlSetState(-1,$GUI_disable) Any suggestion ? Thanks Link to comment Share on other sites More sharing options...
AutoBert Posted June 6, 2016 Share Posted June 6, 2016 use GUICtrlSetState($idFomCtrl, $Gui_DISABLE) Link to comment Share on other sites More sharing options...
Stacker Posted June 6, 2016 Author Share Posted June 6, 2016 Sure, but i need first to read value with this code Local $indexSelected = ControlListView("", "", $idListView, "GetSelected") local $thisSelected = ControlListView("", "", $idListView, "GetText", $indexSelected, 1) and Disable Item when if find a specific value $thisselected. But when i press mouse right button on listview menu appear and can't modify in real time. So i need alternative code.... my not work properly Link to comment Share on other sites More sharing options...
AutoBert Posted June 6, 2016 Share Posted June 6, 2016 post a small runable reproducer showin the issue(s) you have. I thougt it's a LV in a GUI you created, why using ControlListView? Link to comment Share on other sites More sharing options...
Stacker Posted June 6, 2016 Author Share Posted June 6, 2016 sorry, but it's difficult to post a small runable reproducer..... and my code it's very complicated. I read database (sql) and populate the Listview... i try to change routine GUIgetmsg to read Secondary Mouse button and create the Context menu in real time with item enable or disabled dependig to value read in listview Link to comment Share on other sites More sharing options...
orbs Posted June 6, 2016 Share Posted June 6, 2016 48 minutes ago, Stacker said: ... create the Context menu in real time ... sure, that's possible. but perhaps an easier solution would be to display a MsgBox (e.g. "this option is unavailable for the selected item") if someone does select the wished-to-be-disabled context menu item for unsupported list view item. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
Stacker Posted June 7, 2016 Author Share Posted June 7, 2016 it's an idea. If i can't do "real time context menu" Thanks Link to comment Share on other sites More sharing options...
LarsJ Posted June 7, 2016 Share Posted June 7, 2016 Come on. That's easy: expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <GuiMenu.au3> Global $g_hListView, $hGUI Global Enum $eEven = 1000, $eOdd Example() Func Example() $hGUI = GUICreate("(UDF Created) ListView Create", 400, 300) $g_hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 394, 268) _GUICtrlListView_SetExtendedListViewStyle($g_hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) ; Load images Local $hImage = _GUIImageList_Create() _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_hListView, 0xFF0000, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_hListView, 0x00FF00, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_hListView, 0x0000FF, 16, 16)) _GUICtrlListView_SetImageList($g_hListView, $hImage, 1) ; Add columns _GUICtrlListView_InsertColumn($g_hListView, 0, "Column 1", 100) _GUICtrlListView_InsertColumn($g_hListView, 1, "Column 2", 100) _GUICtrlListView_InsertColumn($g_hListView, 2, "Column 3", 100) ; Add items _GUICtrlListView_AddItem($g_hListView, "Row 1: Col 1", 0) _GUICtrlListView_AddSubItem($g_hListView, 0, "Row 1: Col 2", 1) _GUICtrlListView_AddSubItem($g_hListView, 0, "Row 1: Col 3", 2) _GUICtrlListView_AddItem($g_hListView, "Row 2: Col 1", 1) _GUICtrlListView_AddSubItem($g_hListView, 1, "Row 2: Col 2", 1) _GUICtrlListView_AddItem($g_hListView, "Row 3: Col 1", 2) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam Switch _WinAPI_LoWord($wParam) Case $eEven MsgBox( 0, "Item", "Even" ) Case $eOdd MsgBox( 0, "Item", "Odd" ) EndSwitch Return $GUI_RUNDEFMSG EndFunc Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) Local $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $g_hListView Switch $iCode Case $NM_RCLICK Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $iItem = DllStructGetData($tInfo, "Index") If $iItem > -1 Then Local $hMenu = _GUICtrlMenu_CreatePopup(), $bEven = Mod( $iItem, 2 ) = 0 _GUICtrlMenu_InsertMenuItem( $hMenu, 0, "Even", $eEven ) _GUICtrlMenu_SetItemEnabled( $hMenu, 0, $bEven ) _GUICtrlMenu_InsertMenuItem( $hMenu, 1, "Odd", $eOdd ) _GUICtrlMenu_SetItemEnabled( $hMenu, 1, Not $bEven ) _GUICtrlMenu_TrackPopupMenu( $hMenu, $hGUI ) _GUICtrlMenu_DestroyMenu( $hMenu ) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Synapsee, czardas and AutoBert 3 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Stacker Posted June 10, 2016 Author Share Posted June 10, 2016 Wow thanks. I use Opt("GUIOnEventMode", 1) in my code so i think your code can't work. I try Link to comment Share on other sites More sharing options...
AutoBert Posted June 10, 2016 Share Posted June 10, 2016 1 hour ago, Stacker said: I use Opt("GUIOnEventMode", 1) in my code so i think your code can't work. Same in GuiOnEventMode: expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <GuiMenu.au3> Opt("GUIOnEventMode", 1) Global $g_hListView, $hGUI Global Enum $eEven = 1000, $eOdd Example() Func Example() $hGUI = GUICreate("(UDF Created) ListView Create", 400, 300) GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit') $g_hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 394, 268) _GUICtrlListView_SetExtendedListViewStyle($g_hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) ; Load images Local $hImage = _GUIImageList_Create() _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_hListView, 0xFF0000, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_hListView, 0x00FF00, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_hListView, 0x0000FF, 16, 16)) _GUICtrlListView_SetImageList($g_hListView, $hImage, 1) ; Add columns _GUICtrlListView_InsertColumn($g_hListView, 0, "Column 1", 100) _GUICtrlListView_InsertColumn($g_hListView, 1, "Column 2", 100) _GUICtrlListView_InsertColumn($g_hListView, 2, "Column 3", 100) ; Add items _GUICtrlListView_AddItem($g_hListView, "Row 1: Col 1", 0) _GUICtrlListView_AddSubItem($g_hListView, 0, "Row 1: Col 2", 1) _GUICtrlListView_AddSubItem($g_hListView, 0, "Row 1: Col 3", 2) _GUICtrlListView_AddItem($g_hListView, "Row 2: Col 1", 1) _GUICtrlListView_AddSubItem($g_hListView, 1, "Row 2: Col 2", 1) _GUICtrlListView_AddItem($g_hListView, "Row 3: Col 1", 2) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) ; Loop While 1 Sleep(1000) WEnd GUIDelete() EndFunc ;==>Example Func _Exit() Exit EndFunc ;==>_Exit Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam Switch _WinAPI_LoWord($wParam) Case $eEven MsgBox(0, "Item", "Even") Case $eOdd MsgBox(0, "Item", "Odd") EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) Local $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $g_hListView Switch $iCode Case $NM_RCLICK Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $iItem = DllStructGetData($tInfo, "Index") If $iItem > -1 Then Local $hMenu = _GUICtrlMenu_CreatePopup(), $bEven = Mod($iItem, 2) = 0 _GUICtrlMenu_InsertMenuItem($hMenu, 0, "Even", $eEven) _GUICtrlMenu_SetItemEnabled($hMenu, 0, $bEven) _GUICtrlMenu_InsertMenuItem($hMenu, 1, "Odd", $eOdd) _GUICtrlMenu_SetItemEnabled($hMenu, 1, Not $bEven) _GUICtrlMenu_TrackPopupMenu($hMenu, $hGUI) _GUICtrlMenu_DestroyMenu($hMenu) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY MichaelHB 1 Link to comment Share on other sites More sharing options...
Stacker Posted June 13, 2016 Author Share Posted June 13, 2016 Thank you Autobert 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