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

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mrmech
Posts: 81
Joined: 07 Dec 2015, 17:37

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

Post by mrmech » 29 Nov 2022, 08:31

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.
Last edited by mrmech on 29 Nov 2022, 12:33, edited 1 time in total.

NexusP
Posts: 27
Joined: 26 Nov 2020, 09:01

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

Post by NexusP » 29 Nov 2022, 09:10

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
} 

mrmech
Posts: 81
Joined: 07 Dec 2015, 17:37

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

Post by mrmech » 29 Nov 2022, 14:46

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.

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

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

Post by mikeyww » 29 Nov 2022, 15:00

Menu, Delete? And then add it again?

mrmech
Posts: 81
Joined: 07 Dec 2015, 17:37

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

Post by mrmech » 29 Nov 2022, 15:11

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!

lexikos
Posts: 9560
Joined: 30 Sep 2013, 04:07
Contact:

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

Post by lexikos » 29 Nov 2022, 23:42

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.

Post Reply

Return to “Ask for Help (v1)”