Page 1 of 1

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

Posted: 14 Aug 2019, 12:18
by afe
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

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

Posted: 14 Aug 2019, 13:25
by hunter99
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.

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

Posted: 14 Aug 2019, 14:01
by afe
Thank you very much! Before I close Gui2, use Menu, MenuName, DeleteAll to delete all menus and it works.

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

Posted: 16 Aug 2019, 04:19
by afe
Is this a bug?

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

Posted: 18 Aug 2019, 00:02
by lexikos
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.