Page 1 of 1

Menu: How do you hide only one of a menu's submenus?

Posted: 29 Nov 2022, 08:31
by mrmech
I want to show or hide a submenu depending on whether text is selected in a program called ComicRack. My current script works great (thank you AHK forums) but it only disables the submenu (it's greyed out) and I want to hide it entirely:

Code: Select all

If WinActive("ahk_exe ComicRack.exe") {
	Selected_Text := ""
	ControlGet, Selected_Text, Selected,, WindowsForms10.EDIT.app.0.37e3228_r6_ad12, ahk_exe ComicRack.exe
		If ErrorLevel {
		 MsgBox, 48, Error, Missing ControlGet.
		 Return
	} If (Selected_Text = "") {
		Menu,Comics,Disable,Search
		Menu,Comics,Show
	} Else if (Selected_Text)
		Menu,Search,Show
} return
List of Menus:

Code: Select all

Menu,Comics,Add,Formats,Function
	Menu,Formats,Add,Artbook,FunctionFormat
	Menu,Formats,Add,Graphic Novel,FunctionFormat
	Menu,Formats,Add,TPB,FunctionFormat
Menu,Comics,Add,Genres,FunctionGenre
	Menu,Genres,Add,Fantasy,FunctionGenre
	Menu,Genres,Add,,FunctionGenre
	Menu,Genres,Add,Superhero,FunctionGenre
Menu,Comics,Add,Search,Function
	Menu,Search,Add,Google,SearchGoogle
	Menu,Search,Add,Wikipedia,SearchWikipedia
	Menu,Search,Add,Comicvine,SearchComicvine
Also, please feel free to suggest ways to make the script better.

Re: Menu: How do you hide a submenu if text is not selected?

Posted: 29 Nov 2022, 09:10
by NexusP
I did a loop in order to monitor external changes when it came to hiding and showing menu items. Someone more experienced may have a more proper answer.

Code: Select all

loop 
{
  SetTitleMatchMode 2
  DetectHiddenWindows On
  if WinExist("app.ahk ahk_class AutoHotkey") 
  {
    GuiControl, Hide, Start
    GuiControl, Show, Stop
  } 
  else 
  {
    GuiControl, Show, Start
    GuiControl, Hide, Stop
  }	
  sleep, 100
} 

Re: Menu: How do you hide only one of a menu's submenus?

Posted: 29 Nov 2022, 14:46
by mrmech
This is for a tray menu. I don't think guicontrol will work on it and I don't think menu has a hide command.
Thanks for the suggestion though.

Re: Menu: How do you hide only one of a menu's submenus?  Topic is solved

Posted: 29 Nov 2022, 15:00
by mikeyww
Menu, Delete? And then add it again?

Re: Menu: How do you hide only one of a menu's submenus?

Posted: 29 Nov 2022, 15:11
by mrmech
It worked! I misread the article and thought it only deleted custom parts of the menu like DeleteAll:
[url]https://.autohotkey.com/docs/commands/Menu.htm#Delete[/url]

Code: Select all

If WinActive("ahk_exe ComicRack.exe") {
	Selected_Text := ""
	ControlGet, Selected_Text, Selected,, WindowsForms10.EDIT.app.0.37e3228_r6_ad12, ahk_exe ComicRack.exe
		If ErrorLevel {
		 MsgBox, 48, Error, Missing ControlGet.
		 Return
	} If (Selected_Text = "") {
		Menu,Comics,Delete,Search ; <--------------- FIXED
		Menu,Comics,Show
	} Else if (Selected_Text)
		Menu,Search,Show
} return
Thanks again!

Re: Menu: How do you hide only one of a menu's submenus?

Posted: 29 Nov 2022, 23:42
by lexikos
I misread the article and thought it only deleted custom parts of the menu like DeleteAll:
Delete in v1 only deletes custom menu items. "Search" is a custom menu item (one you added to the Menu with the Add sub-command), not a standard item (in the Tray menu by default, or added with the "Standard" subcommand).

Delete in v2 is able to delete standard items.