Will the context menu be destroyed when the GUI is destroyed? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
afe
Posts: 574
Joined: 06 Dec 2018, 04:36

Will the context menu be destroyed when the GUI is destroyed?

14 Aug 2019, 12:18

Hello,

Will the context menu be destroyed when the GUI is destroyed ? I found the following example, each time I re-open Gui2 and right click, its context menu will add a new line at the bottom. Why ?

Code: Select all

Gui, Add, Button,, Open
Gui, Show, h300 w400
return

ButtonOpen:
Gui, 1:-Disabled
Gui, 2:Default
Gui, +Owner1
Gui, Add, ListView, r10 w300, Title
Menu, ContextMenu, Add, Open, Open
Menu, ContextMenu, Add
Menu, ContextMenu, Add, Save, Save
Gui, Show
return

2GuiClose:
Gui, 1:-Disabled
Gui, Destroy
return

2GuiContextMenu:
Menu, ContextMenu, Show
return

Open:
return

Save:
return
hunter99
Posts: 126
Joined: 20 Jan 2014, 17:57

Re: Will the context menu be destroyed when the GUI is destroyed?  Topic is solved

14 Aug 2019, 13:25

Hi afe, this should do it.
See GEV's answer here : https://autohotkey.com/board/topic/105748-my-menu-is-keeps-growing/

hunter99

Edit: a few lines and comments from a script wrote a few years ago.

Menu, rcMenu, Add ;Would add another line with each usage; pulling out my hair, then found this:
Menu, rcMenu, deleteAll ;https://autohotkey.com/board/topic/105748-my-menu-is-keeps-growing/ - THANK You GEV!
Menu, rcMenu, add, %A_ScriptFullPath%, Dummy ;add dummy label as we just want to show text.
afe
Posts: 574
Joined: 06 Dec 2018, 04:36

Re: Will the context menu be destroyed when the GUI is destroyed?

14 Aug 2019, 14:01

Thank you very much! Before I close Gui2, use Menu, MenuName, DeleteAll to delete all menus and it works.
lexikos
Posts: 6652
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Will the context menu be destroyed when the GUI is destroyed?

18 Aug 2019, 00:02

Menu, ContextMenu, Add, Open, Open
Menu, ContextMenu, Add
Menu, ContextMenu, Add, Save, Save
This code adds or updates menu items in a menu, creating the menu if it doesn't already exist. For the "Open" and "Save" items, if items with those names already exist, they are updated (but nothing actually changes because the parameters are the same). The second item has no name, so every time you execute this line, a new separator item is added to the menu.
Menu, ContextMenu, Show
This code shows the menu.

There is nothing at all linking the menu to the GUI. You call it a context menu, but it's only that because of when you happen to show it. It's just a menu.

So no, the menu will not be destroyed unless you destroy it, and this is not a bug.

Return to “Ask For Help”

Who is online

Users browsing this forum: flyingDman, spectequila and 186 guests