March 28, 2024, 01:30:55 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Disabling / Enabling context menu items

Started by Andy, September 18, 2017, 11:40:37 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

September 18, 2017, 11:40:37 PM Last Edit: September 19, 2017, 06:41:39 AM by Andy
I have a control (Tree view) and it's sub classed so I can create a context menu for it, like this:

sub KeyContextMenu(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam,UINT_PTR uIdSubclass,DWORD_PTR dwRefData)
Select uMsg
case WM_RBUTTONDOWN
  POINT cursor
  GetCursorPos(cursor)
  ScreenToClient(win.hwnd, cursor)
  CONTEXTMENU win,cursor.x, cursor.y
   MENUITEM "Add key",0,106
   MENUITEM "Copy key",0,107
   MENUITEM "Rename key",0,108
   MENUITEM "Delete key",0,109
  ENDMENU
           return

Case WM_DESTROY
  RemoveWindowSubclass(hWnd,&KeyContextMenu,SUBCLASS2_ID)

EndSelect
Return DefSubclassProc(hWnd,uMsg,wParam,lParam)
EndSub


But at times, I want to disable say "Add Key".

Now iv'e tried ENABLEMENUITEM with a Zero, but that doesn't seem to work.

I could just destroy the sub class and create a new one with only the options I want in, but is there a way to do disable a context menu item without destroying the sub class?

BTW, I'm getting very close now to releasing the registry library file and the new Registry viewer and editor - for those of you who might be interested.

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

This sort of structure should let you do what you want.
sub KeyContextMenu(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam,UINT_PTR uIdSubclass,DWORD_PTR dwRefData)
    Select uMsg
      case WM_RBUTTONDOWN
           POINT cursor
           GetCursorPos(cursor)
           ScreenToClient(win.hwnd, cursor)
         selstart = CallScintilla(win_sci,SCI_GETSELECTIONSTART,0,0)
         selend =  CallScintilla(win_sci,SCI_GETSELECTIONEND,0,0)
         CallScintilla(win_sci,SCI_GETSELTEXT,0,&snip)
         if snip<>""
            searchterm=left$(snip,250)
            sterm=1
         endif
         canundo = CallScintilla(win_sci,SCI_CanUndo,0,0)
         canredo = CallScintilla(win_sci,SCI_CanRedo,0,0)
         canpaste = CallScintilla(win_sci,SCI_CanPaste,0,0)
         if activedb=1     ' this could be a SELECT statement
            ContextMenu win_sci, pt.x,pt.y
               MenuItem "Copy\tCtrl-C",(selstart=selend)*@MENUDISABLE,MENU_COPY
               MenuItem "Select All\tCtrl-A",0,MENU_SELECTALL
               Separator
               MenuItem "Find\tCtrl-F",0,MENU_FIND
               Separator
               MenuItem "Find First\tF2",!sterm*@MENUDISABLE,MENU_FINDFIRST    'by having a different flag for each menu item
               MenuItem "Find Prev\tF4",!sterm*@MENUDISABLE,MENU_FINDPREV     'you could change multiple menu items in one
               MenuItem "Find Next\tF3",!sterm*@MENUDISABLE,MENU_FINDNEXT     'contexmenu without any problem if you like
               MenuItem "Find Last\tF5",!sterm*@MENUDISABLE,MENU_FINDLAST
               Separator
               MenuItem "Find in Help\tF1",!sterm*@MENUDISABLE,MENU_FINDHELP
            endmenu
         else
            ContextMenu win_sci, pt.x,pt.y
               MenuItem "Undo",(canundo=0) * @MENUDISABLE,MENU_UNDO
               MenuItem "Redo",(canredo=0) * @MENUDISABLE,MENU_REDO
               Separator
               MenuItem "Cut\tCtrl-X",(selstart=selend)*@MENUDISABLE,MENU_CUT
               MenuItem "Copy\tCtrl-C",(selstart=selend)*@MENUDISABLE,MENU_COPY
               MenuItem "Paste\tCtrl-V",(canpaste=0)*@MENUDISABLE,MENU_PASTE
               MenuItem "Select All\tCtrl-A",0,MENU_SELECTALL
               Separator
               MenuItem "Find\tCtrl-F",0,MENU_FIND
               Separator
               MenuItem "Find First\tF2",!sterm*@MENUDISABLE,MENU_FINDFIRST
               MenuItem "Find Prev\tF4",!sterm*@MENUDISABLE,MENU_FINDPREV
               MenuItem "Find Next\tF3",!sterm*@MENUDISABLE,MENU_FINDNEXT
               MenuItem "Find Last\tF5",!sterm*@MENUDISABLE,MENU_FINDLAST
               Separator
               MenuItem "Find in Help...",!sterm*@MENUDISABLE,MENU_FINDHELP
            endmenu
         endif
           return

      Case WM_DESTROY
           RemoveWindowSubclass(hWnd,&KeyContextMenu,SUBCLASS2_ID)

    EndSelect
    Return DefSubclassProc(hWnd,uMsg,wParam,lParam)
EndSub

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Thanks Larry,

Will have a look at that, just having fun and games at the moment with the tree view control i.e. getting it to do what I want - but getting there slowly.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.