-
Notifications
You must be signed in to change notification settings - Fork 72
/
CB.ahk
139 lines (123 loc) · 5.4 KB
/
CB.ahk
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* ComboBox / DropDownList Manipulation functions
- heresy
-Common Parameters
Control : ClassNN of Control (default=ComboBox1)
Window : WinTitle of the window (default=ahk_class AutoHotkeyGUI)
Pos : Sel of the Box, usually starts from 0 (-1 = currentsel by default)
String : String to be added/inserted/modified with
-Functions
CB_Get(Control="ComboBox1", Window="ahk_class AutoHotkeyGUI")
Return current selected position
CB_Set(Pos=0, Control="ComboBox1", Window="ahk_class AutoHotkeyGUI")
Set selected position to %Position%
CB_Add(String="", Control="ComboBox1", Window="ahk_class AutoHotkeyGUI")
Add %String% to the end
CB_Insert(String="", Pos=-1, Control="ComboBox1", Window="ahk_class AutoHotkeyGUI")
Insert %String% at specified %Position%
CB_Modify(String="", Pos=-1, Control="ComboBox1", Window="ahk_class AutoHotkeyGUI")
Modify entry of specified %Position% to %String%
CB_Delete(Pos=-1, Control="ComboBox1", Window="ahk_class AutoHotkeyGUI")
Delete entry of specified %Position%
CB_Reset(Control="ComboBox1", Window="ahk_class AutoHotkeyGUI")
Reset (delete all)
CB_Find(String, Control="ComboBox1", Window="ahk_class AutoHotkeyGUI")
Find position of %String%
CB_FindExact(String, Control="ComboBox1", Window="ahk_class AutoHotkeyGUI")
Same as above but more accuracy
CB_Select(String, Control="ComboBox1", Window="ahk_class AutoHotkeyGUI")
Find %String% and Select automatically
equivalent to (GuiControl, ChooseString, ControlID, String)
CB_Show(Flag=True, Control="ComboBox1", Window="ahk_class AutoHotkeyGUI")
Show DropDown or Hide(Flag=False)
CB_GetCount(Control="ComboBox1", Window="ahk_class AutoHotkeyGUI")
Return total count of the entries
CB_GetText(Pos=-1, Control="ComboBox1", Window="ahk_class AutoHotkeyGUI")
Return text of the specified %Position%
CB_GetTexts(delimiter="`n", Control="ComboBox1", Window="ahk_class AutoHotkeyGUI")
Return text of all entries
*/
CB_Get(Control="ComboBox1", Window="ahk_class AutoHotkeyGUI"){
SendMessage, 0x147,,, %Control%, %Window% ;CB_GETCURSEL
Return Errorlevel
}
CB_Set(Pos=0, Control="ComboBox1", Window="ahk_class AutoHotkeyGUI"){
SendMessage, 0x14E, %Pos%,, %Control%, %Window% ;CB_SETCURSEL
Return Errorlevel
}
CB_Add(String="", Control="ComboBox1", Window="ahk_class AutoHotkeyGUI"){
SendMessage, 0x143,, &String, %Control%, %Window% ;CB_ADDSTRING
Result := Errorlevel
CB_Set(Errorlevel, Control, Window)
Return Result
}
CB_Insert(String="", Pos=-1, Control="ComboBox1", Window="ahk_class AutoHotkeyGUI"){
if Pos=-1
Pos := CB_Get(Control, Window)
SendMessage, 0x14A, %Pos%, &String, %Control%, %Window% ;CB_INSERTSTRING
Result := Errorlevel
CB_Set(Pos, Control, Window)
Return Result
}
CB_Modify(String="", Pos=-1, Control="ComboBox1", Window="ahk_class AutoHotkeyGUI"){
if Pos=-1
Pos := CB_Get(Control, Window)
SendMessage, 0x144, %Pos%,, %Control%, %Window% ;CB_DELETESTRING
SendMessage, 0x14A, %Pos%, &String, %Control%, %Window% ;CB_INSERTSTRING
Result := Errorlevel
CB_Set(Pos, Control, Window)
Return Result
}
CB_Delete(Pos=-1, Control="ComboBox1", Window="ahk_class AutoHotkeyGUI"){
if Pos=-1
Pos := CB_Get(Control, Window)
SendMessage, 0x144, %Pos%,, %Control%, %Window% ;CB_DELETESTRING
Result := Errorlevel
CB_Set(Pos, Control, Window)
Return Result
}
CB_Reset(Control="ComboBox1", Window="ahk_class AutoHotkeyGUI"){
SendMessage, 0x14B,,, %Control%, %Window% ;CB_RESETCONTENT
Return Errorlevel
}
CB_Find(String, Control="ComboBox1", Window="ahk_class AutoHotkeyGUI"){
SendMessage, 0x14C,, &String, %Control%, %Window%
Result := Errorlevel
Return (Result > CB_GetCount(Control, Window)) ? -1 : Result
}
CB_FindExact(String, Control="ComboBox1", Window="ahk_class AutoHotkeyGUI"){
SendMessage, 0x158,, &String, %Control%, %Window%
Result := Errorlevel
Return (Result > CB_GetCount(Control, Window)) ? -1 : Result
}
CB_Select(String, Control="ComboBox1", Window="ahk_class AutoHotkeyGUI"){
SendMessage, 0x14D,, &String, %Control%, %Window%
Return Errorlevel
}
CB_Show(Flag=True, Control="ComboBox1", Window="ahk_class AutoHotkeyGUI"){
SendMessage, 0x14F, %Flag%,, %Control%, %Window% ;CB_SHOWDROPDOWN
Return Errorlevel
}
CB_GetCount(Control="ComboBox1", Window="ahk_class AutoHotkeyGUI"){
SendMessage, 0x146,,, %Control%, %Window% ;CB_GETCOUNT
Return Errorlevel
}
CB_GetText(Pos=-1, Control="ComboBox1", Window="ahk_class AutoHotkeyGUI"){
if Pos=-1
Pos := CB_Get(Control, Window)
SendMessage, 0x149, %Pos%,, %Control%, %Window% ;CB_GETLBTEXTLEN
VarSetCapacity(buffer, Errorlevel) ;prepare buffer
SendMessage,0x148, %Pos%, &buffer, %Control%, %Window% ;CB_GETLBTEXT
Return buffer
}
CB_GetTexts(delimiter="`n", Control="ComboBox1", Window="ahk_class AutoHotkeyGUI"){
Loop, % CB_GetCount(Control, Window)
{
SendMessage, 0x149, % A_Index-1,, %Control%, %Window% ;CB_GETLBTEXTLEN
VarSetCapacity(buffer, Errorlevel) ;prepare buffer
SendMessage, 0x148, % A_Index-1, &buffer, %Control%, %Window% ;CB_GETLBTEXT
Result .= buffer . delimiter
VarSetCapacity(buffer,0) ;empty for next wheel
}
StringTrimRight, Result, Result, % StrLen(delimiter) ;remove tail
Return Result
}