=sinister= Posted September 30, 2009 Share Posted September 30, 2009 I have a Context Menu and a few items under it, and when i use "GUICtrlSetState($ContextItem, $GUI_DISABLE)", I have to scroll over the item for it to show as grayed out. So, is there a way to show it as grayed out before the menu shows? Part of my code: $Context = GUICtrlCreateContextMenu($VideoList) ;//Context menu is part of a listview btw. $ContextAdd = GUICtrlCreateMenuItem("Add Video", $Context) $ContextDelete = GUICtrlCreateMenuItem("Delete", $Context) bla bla GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU") script script stuff stuff script script Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam) GUICtrlSetState($ContextDelete, $GUI_ENABLE) If _GUICtrlListView_GetSelectedIndices($VideoList) = 0 Then GUICtrlSetState($ContextDelete, $GUI_DISABLE) EndIf EndFunc ;==>WM_CONTEXTMENU Link to comment Share on other sites More sharing options...
smashly Posted September 30, 2009 Share Posted September 30, 2009 Hi, sorry for the length of the code, but I just adapted a bit of code I had on handexpandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Global $iLV, $iCtxt0, $iCtxt1, $msg, $iSelCnt, $sTmp GUICreate(":-)", 400, 300) $iLV = GUICtrlCreateListView("Item #|Data 1|Data 2", 5, 5, 390, 290, $LVS_SHOWSELALWAYS) $iCtxt0 = GUICtrlCreateContextMenu($iLV) $iCtxt1 = GUICtrlCreateMenuItem("Copy", $iLV) For $i = 1 To 5 GUICtrlCreateListViewItem($i & "|Item " & $i & "'s Data 1|Item " & $i & "'s Data 2", $iLV) Next GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $iCtxt1 $iSelCnt = _GUICtrlListView_GetSelectedCount($iLV) Switch $iSelCnt Case 1 ClipPut(_GUICtrlListView_GetItemTextString($iLV)) Case 2 To $iSelCnt $sTmp = '' For $i = 1 To UBound(_GUICtrlListView_GetSelectedIndices($iLV, True)) - 1 $sTmp &= _GUICtrlListView_GetItemTextString($iLV, $i - 1) & @CRLF Next ClipPut(StringStripWS($sTmp, 2)) EndSwitch EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hLV $hLV = GUICtrlGetHandle($iLV) $tNMHDR = DllStructCreate("hwnd hWndFrom;int_ptr IDFrom;int Code", $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hLV Switch $iCode Case $NM_RCLICK If _GUICtrlListView_GetSelectedCount($hLV) Then If BitAND(GUICtrlRead($iCtxt1), $GUI_DISABLE) Then GUICtrlSetState($iCtxt1, $GUI_ENABLE) Else If BitAND(GUICtrlRead($iCtxt1), $GUI_ENABLE) Then GUICtrlSetState($iCtxt1, $GUI_DISABLE) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Cheers Link to comment Share on other sites More sharing options...
=sinister= Posted September 30, 2009 Author Share Posted September 30, 2009 Works perfectly, thank you very much 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