Deleting menu items when a Process Name is detected. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
XMCQCX
Posts: 258
Joined: 14 Oct 2020, 23:44

Deleting menu items when a Process Name is detected.

Post by XMCQCX » 31 May 2021, 16:35

Hi,
how to hide a menu item when a Process Name is not detected. Deleted Item1 when the variable "ProcessNameEXE" does not equal "Explorer.EXE" Why it's not working ? Any help is appreciated.

Code: Select all

Menu, MyMenu, Add, Item1, MenuHandler1
if (ProcessNameEXE != Explorer.EXE) {
Menu, MyMenu, Delete, Item1
}
Menu, MyMenu, Add, Item2, MenuHandler2
Return

MenuHandler1:
return

MenuHandler2:
return

MButton:: 
MouseGetPos, xpos, ypos, Window, ClassNN
WinGet, ProcessNameEXE, ProcessName, ahk_id %Window%
Msgbox, %ProcessNameEXE%
Menu, MyMenu, Show
Last edited by XMCQCX on 31 May 2021, 17:17, edited 1 time in total.

WatsonEnterprises
Posts: 19
Joined: 25 May 2020, 23:04

Re: Deleting menu items when a Process Name is detected.  Topic is solved

Post by WatsonEnterprises » 31 May 2021, 17:16

In your script, the menu is only built once (at the top of the script) and it never changes. If you want the items to change, you need to check the process name and add/delete items accordingly every time before showing it. (That, and you're missing quotes for string comparison against "Explorer.EXE")

Code: Select all

MButton::BuildMyMenuAndShowIt()

BuildMyMenuAndShowIt(){
	Menu, MyMenu, Add   ;to avoid "menu does not exist" error with DeleteAll
	Menu, MyMenu, DeleteAll
	
	MouseGetPos, xpos, ypos, Window, ClassNN
	WinGet, ProcessNameEXE, ProcessName, ahk_id %Window%
	Msgbox, %ProcessNameEXE%
	
	Menu, MyMenu, Add, Item1, MenuHandler1
	if (ProcessNameEXE = "Explorer.EXE") {
		Menu, MyMenu, Delete, Item1
	}
	Menu, MyMenu, Add, Item2, MenuHandler2
	
	Menu, MyMenu, Show
}

MenuHandler1:
return
MenuHandler2:
return

XMCQCX
Posts: 258
Joined: 14 Oct 2020, 23:44

Re: Deleting menu items when a Process Name is detected.

Post by XMCQCX » 31 May 2021, 17:26

WatsonEnterprises wrote:
31 May 2021, 17:16
In your script, the menu is only built once (at the top of the script) and it never changes. If you want the items to change, you need to check the process name and add/delete items accordingly every time before showing it. (That, and you're missing quotes for string comparison against "Explorer.EXE")
Thank you very much for the help, WatsonEnterprises. It's very appreciated !

Post Reply

Return to “Ask for Help (v1)”