-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMenuExample.ahk
More file actions
98 lines (81 loc) · 2.25 KB
/
MenuExample.ahk
File metadata and controls
98 lines (81 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
SetBatchlines, -1
MyWindow := new CMenuExample("Menu Example") ;Create an instance of this window class
return
#include <CGUI>
Class CMenuExample Extends CGUI
{
BtnTest := this.AddControl("Button", "BtnTest", "", "Button1 with static menu")
BtnTest2 := this.AddControl("Button", "BtnTest2", "", "Button2 with dynamic menu")
__New(Title)
{
this.Title := Title
this.Resize := true
this.MinSize := "200x100"
this.CloseOnEscape := true
this.DestroyOnClose := true
;Creating a menu
Menu1 := new CMenu("Main")
;Adding a menu item
Menu1.AddMenuItem("hello", "test")
;Accessing a menu item and setting some of its properties
Menu1[1].Text := "Test"
Menu1[1].Checked := true
Menu1[1].Enabled := false
;Adding a submenu
Menu1.AddSubMenu("sub1", "Test")
Menu1[2].AddMenuItem("blup", "blup")
sub2 := New CMenu("sub2")
sub2.AddMenuItem("blah", "blah")
;Adding an existing menu as submenu
Menu1.AddSubMenu("sub2", sub2)
;Setting a menu's icon
sub2.Icon := A_AHKPath
;Deleting a menu item
Menu1.DeleteMenuItem(1)
;By setting the Menu property of a CGUI or CControl instance this menu will be shown as context menu automatically.
this.BtnTest.Menu := Menu1
;~ this.Menu(this.Menu1) ;Menu can't be used for context and menu bar at once!
this.Show("")
}
;Called when the context menu of the edit control is to be invoked. Functions like this are used if the menu needs to be dynamically generated.
BtnTest2_ContextMenu()
{
;Make sure that we don't try to create the same menu twice by deleting an old instance
if(IsObject(this.DynamicMenu))
this.DynamicMenu.DisposeMenu()
;Create the menu and show it
this.DynamicMenu := New CMenu("test2")
this.DynamicMenu.AddMenuItem("MenuItem", "MenuItem")
this.ShowMenu(this.DynamicMenu)
}
BtnTest_Click()
{
MsgBox % "You left-clicked Button1`nTry right click!"
}
BtnTest2_Click()
{
MsgBox % "You left-clicked Button2`nTry right click!"
}
;The functions below are called when the matching menu item was selected.
blup()
{
MsgBox blup
}
test()
{
MsgBox hello
}
blah()
{
MsgBox blah
}
MenuItem()
{
MsgBox MenuItem
}
PostDestroy()
{
if(!this.Instances.MaxIndex()) ;Exit when all instances of this window are closed
ExitApp
}
}