Jump to content

Context Menu How to Hide a menu option


MacScript
 Share

Recommended Posts

HI there, I was wondering if there is a way to hide a menu option that is part of a context menu. For instance when you right click on the body of this gui and set Readonly = Yes. Then I want the COntext Menu for New to be Hidden (Not disabled/greyed out). Is there any way to do this?

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
Example()
Func Example()
    GUICreate("My GUI Context Menu", 300, 200)

    Local $idContextmenu = GUICtrlCreateContextMenu()
    Global $CtxMenuTrans = GUICtrlCreateMenu("Read Only", $idContextmenu)   ;-45a-
    Global $CtxMenuNo = GUICtrlCreateMenuItem("No", $CtxMenuTrans, -1, 1)   ;-49b-
    Global $CtxMenuYes = GUICtrlCreateMenuItem("Yes", $CtxMenuTrans, -1, 1) ;-49b-
    GUICtrlSetState($CtxMenuNo, $GUI_CHECKED)   ;-49b-
    Local $idNewsubmenu = GUICtrlCreateMenu("new", $idContextmenu)
    Local $idNewsubmenuText = GUICtrlCreateMenuItem("text", $idNewsubmenu)
    Local $idButton = GUICtrlCreateButton("OK", 100, 100, 70, 20)
    Local $idButtoncontext = GUICtrlCreateContextMenu($idButton)
    Local $idMenuAbout = GUICtrlCreateMenuItem("About button", $idButtoncontext)
    Local $idMenuOpen = GUICtrlCreateMenuItem("Open", $idContextmenu)
    Local $idMenuSave = GUICtrlCreateMenuItem("Save", $idContextmenu)
    GUICtrlCreateMenuItem("", $idContextmenu) ; separator
    Local $idMenuInfo = GUICtrlCreateMenuItem("Info", $idContextmenu)
    GUISetState(@SW_SHOW)
    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $CtxMenuNo
                ;----> Show the Control $idNewsubmenu <----
            Case $CtxMenuyes
                ;----> HIDE the Control $idNewsubmenu <----
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idButton
                MsgBox($MB_SYSTEMMODAL, "Button Clicked", 'OK')
            Case $idMenuAbout
                MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'About')
            Case $idMenuOpen
                MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Open')
            Case $idMenuSave
                MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Save')
            Case $idMenuInfo
                MsgBox($MB_SYSTEMMODAL, "Menu Selected", 'Info')
            Case $idNewsubmenuText
                MsgBox($MB_SYSTEMMODAL, "SubMenu Selected", 'Text')
        EndSwitch
    WEnd
    GUIDelete()
EndFunc   ;==>Example

Thanks in advance for any help / suggestions that are provided :)

Link to comment
Share on other sites

This will hide the control that you pass to it (I passed the new context menu per your question):

GUICtrlSetState($idNewsubmenu, 32)

Here is the helpfile link

EDIT: you would add this to your case statement that when pressed; you want it to do this ^

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Understood, should have looked ><, I will keep looking :)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

There is no way to change the state; the only thing that can be done is to actually delete them and then re-add them.

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

This will essentially 'hide' it by deleting it. If you need to re-add it then you'll need to create it again.

GUICtrlDelete($idNewsubmenu)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...