2 Menus at the same time

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

2 Menus at the same time

Post by hemsith14_ » 24 Jan 2022, 21:15

Hey, I want to view 2 menus side by side, and therefore I tried to do it by creating 2 menus and showing them at different positions.
The problem is that it would show one menu, and then I have to click somewhere else so the second menu will appear while the first one disappears.

Here's my code:

Code: Select all

^1::
CoordMode, Menu
MouseGetPos, MenuX, MenuY
MenuX+=200
Menu, Menu1, Show
Menu, Menu2, Show, %MenuPositionX%
Return
Any help would be appreciated.

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

Re: 2 Menus at the same time

Post by mikeyww » 24 Jan 2022, 21:20

To my knowledge, one standard menu can be shown at a time, but you can provide as many concurrent GUIs as you like. A standard menu must be resolved before proceeding. As far as I know, that is a "feature" of Windows rather than AHK itself.
Last edited by mikeyww on 24 Jan 2022, 21:24, edited 1 time in total.

hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

Re: 2 Menus at the same time

Post by hemsith14_ » 24 Jan 2022, 21:23

No way around it?

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

Re: 2 Menus at the same time

Post by mikeyww » 24 Jan 2022, 21:27

I am not aware of a way to accommodate that with this standard menu system-- or even how the user would interact with two menus at the same time. The menus do not persist as windows in that way. Others here on the forum may have advice or tricks. If you don't have a lot of submenus, then GUI is an easy workaround. Even with many submenus, a treeview can be used as an alternative.

hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

Re: 2 Menus at the same time

Post by hemsith14_ » 24 Jan 2022, 21:30

I feel like GUI is over-complicating it a bit. What would you do if you wanted to show 2 menus side by side?

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

Re: 2 Menus at the same time

Post by mikeyww » 24 Jan 2022, 21:41

Code: Select all

item1 := ["Item1", "Item2", "Item3", "Item4", "Item5", "Item6"]
item2 := ["Item7", "Item8", "Item9", "Item10", "Item11", "Item12"]
Loop, 2 {
 gui := A_Index
 Gui, %gui%:New,, Selection %gui%
 Gui, Font, s10
 For each, itemName in item%gui%
  Gui, Add, Radio, % each = 1 ? "vsel" gui : "", %itemName%
 Gui, Add, Button, w250 Default, OK
}
Gui, 1:Show, x200
Gui, 2:Show, x700
Return
ButtonOK:
Gui, Submit
MsgBox, 64, Selection 1, % item1[sel1]
Return
2ButtonOK:
Gui, 2:Submit
MsgBox, 64, Selection 2, % item2[sel2]
Return
Or:

Code: Select all

item := []
item.Push(["Item01", "Item02", "Item03", "Item04", "Item05", "Item06"])
item.Push(["Item07", "Item08", "Item09", "Item10", "Item11", "Item12"])
For guiNumber, gui in item {
 Gui, %guiNumber%:New,, Selection %guiNumber%
 Gui, Font, s10
 For each, itemName in gui
  Gui, Add, Radio, % each = 1 ? "vsel" guiNumber : "", %itemName%
 Gui, Add, Button, w250 Default, OK
}
Gui, 1:Show, x200
Gui, 2:Show, x700
Return
ButtonOK:
Gui, Submit
MsgBox, 64, Selection 1, % item[1, sel1]
Return
2ButtonOK:
Gui, 2:Submit
MsgBox, 64, Selection 2, % item[2, sel2]
Return
Last edited by mikeyww on 24 Jan 2022, 21:49, edited 1 time in total.

hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

Re: 2 Menus at the same time

Post by hemsith14_ » 24 Jan 2022, 21:48

I see, thanks for the attempt. I still hope to get it sorted with menus some how, and if not, I'll just use one.

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

Re: 2 Menus at the same time

Post by mikeyww » 25 Jan 2022, 08:39

A function is also possible.

Code: Select all

guiMenu(200, 200, "Item1", "Item2", "Item3")
guiMenu(650, 200, "Item4", "Item5", "Item6")
Return

guiMenu(x, y, list*) {
 Global
 Static choice := []
 Gui, New, +HwndhWnd, Selection
 Gui, Font, s10
 For each, item in list {
  Gui, Add, Radio, % each = 1 ? "v" hWnd : "", %item%
  choice[hWnd, each] := item
 }
 Gui, Add, Button, w250 Default gOK, OK
 Gui, Show, x%x% y%y%
 Return
 OK:
 Gui, Submit
 item := choice[A_Gui][%A_Gui%]
 MsgBox, 64, Selection, %item%
 Return
}
Or:

Code: Select all

guiMenu(1, 200, 200, "Item1", "Item2", "Item3")
guiMenu(2, 650, 200, "Item4", "Item5", "Item6")
While WinExist("Selection ahk_class AutoHotkeyGUI")
 Sleep, 250
MsgBox, 64, Selections, % choice.1.0 "`n" choice.2.0
Return

guiMenu(menuNumber, x, y, list*) { ; https://www.autohotkey.com/boards/viewtopic.php?p=441210#p441210
 Global
 choice := choice ? choice : {}
 Gui, %menuNumber%:New,, Selection %menuNumber%
 Gui, Font, s10
 For each, item in list {
  Gui, Add, Radio, % each = 1 ? "v" menuNumber : "", %item%
  choice[menuNumber, each] := item
 }
 Gui, Add, Button, w250 Default gOK, OK
 Gui, Show, x%x% y%y%
 Return
 OK:
 Gui, Submit
 choice[A_Gui].0 := choice[A_Gui][%A_Gui%]
 Return
}

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: 2 Menus at the same time

Post by BoBo » 25 Jan 2022, 14:42

[brainfart] If your two "Menus" are at a fixed position you could create a single GUI with a transparent 'click-through' mid-section. [/brainfart]

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

Re: 2 Menus at the same time

Post by mikeyww » 25 Jan 2022, 15:08

A great idea as well! Or just two different radio groups in one GUI might be fine, too.

Post Reply

Return to “Ask for Help (v1)”