Jump to content

Recommended Posts

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

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

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

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

Come on. That's easy:

#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

 

Link to comment
Share on other sites

1 hour ago, Stacker said:

I use Opt("GUIOnEventMode", 1) in my code so i think your code can't work.

Same in GuiOnEventMode:

#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

 

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

×
×
  • Create New...