├── LICENSE ├── Examples ├── Toolbar_Demo_Simple.ahk └── Toolbar_Demo.ahk ├── README.md └── Class_Toolbar.ahk /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /Examples/Toolbar_Demo_Simple.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv 2 | #SingleInstance, Force 3 | #Include ..\Class_Toolbar.ahk 4 | 5 | ; Create an ImageList. 6 | ILA := IL_Create(4, 2, True) 7 | IL_Add(ILA, "shell32.dll", 127) 8 | IL_Add(ILA, "shell32.dll", 128) 9 | IL_Add(ILA, "shell32.dll", 129) 10 | IL_Add(ILA, "shell32.dll", 130) 11 | 12 | ; TBSTYLE_FLAT := 0x0800 Required to show separators as bars. 13 | ; TBSTYLE_TOOLTIPS := 0x0100 Required to show Tooltips. 14 | Gui, Add, Custom, ClassToolbarWindow32 hwndhToolbar 0x0800 0x0100 15 | Gui, Add, Text, xm, Press F1 to customize. 16 | Gui, Show,, Test 17 | 18 | ; Initialize Toolbars. 19 | ; The variable you choose will be your handle to access the class for your toolbar. 20 | MyToolbar := New Toolbar(hToolbar) 21 | 22 | ; Set ImageList. 23 | MyToolbar.SetImageList(ILA) 24 | 25 | ; Add buttons. 26 | MyToolbar.Add("", "Label1=Button 1:1", "Label2=Button 2:2", "Label3=Button 3:3", "MyFunction=Button 4:4") 27 | 28 | ; Removes text labels and show them as tooltips. 29 | MyToolbar.SetMaxTextRows(0) 30 | 31 | ; Set a function to monitor the Toolbar's messages. 32 | WM_COMMAND := 0x111 33 | OnMessage(WM_COMMAND, "TB_Messages") 34 | 35 | ; Set a function to monitor notifications. 36 | WM_NOTIFY := 0x4E 37 | OnMessage(WM_NOTIFY, "TB_Notify") 38 | 39 | return 40 | 41 | ; This function will receive the messages sent by both Toolbar's buttons. 42 | TB_Messages(wParam, lParam) 43 | { 44 | Global ; Function (or at least the Handles) must be global. 45 | Static Counter := 0 46 | MyToolbar.OnMessage(wParam, ++Counter, A_Hour, A_Min, A_Sec) ; Handles toolbar's messages. 47 | ; If you pass a function as the label, you can also pass any number 48 | ; of parameters starting from 2nd parameter of OnMessage() method. 49 | } 50 | 51 | ; This function will receive the notifications. 52 | TB_Notify(wParam, lParam) 53 | { 54 | Global ; Function (or at least the Handles) must be global. 55 | ReturnCode := MyToolbar.OnNotify(lParam) ; Handles notifications. 56 | return ReturnCode 57 | } 58 | 59 | ; Your labels. 60 | Label1: 61 | Label2: 62 | Label3: 63 | MsgBox, You selected %A_ThisLabel% 64 | return 65 | 66 | ; You can also use a function to be triggered by the button. 67 | MyFunction(x, h, m, s) 68 | { 69 | 70 | MsgBox, You selected %A_ThisFunc% %x% times.`nLast time at %h%:%m%:%s% 71 | } 72 | 73 | ; Customize dialog. 74 | F1::MyToolbar.Customize() 75 | 76 | GuiClose: 77 | ExitApp 78 | return -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Class Toolbar 2 | 3 | ## Class for AutoHotkey Toolbar custom controls 4 | 5 | AHK version: 1.1.23.01 6 | 7 | This class provides intuitive methods to work with Toolbar controls created via **Gui, Add, Custom, ClassToolbarWindow32**. 8 | 9 | Note: It's recommended to call any method only after Gui, Show. Adding or modifying buttons of a toolbar in a Gui that is not yet visible might fail eventually. 10 | 11 | ## Toolbar Methods: 12 | * Add([Options, Label1[=Text]:Icon[(Options)], Label2[=Text]:Icon[(Options)]...]) 13 | * AutoSize() 14 | * Customize() 15 | * Delete(Button) 16 | * Export() 17 | * Get([HotItem, TextRows, Rows, BtnWidth, BtnHeight, Style, ExStyle]) 18 | * GetButton(Button [, ID, Text, State, Style, Icon, Label, Index]) 19 | * GetButtonPos(Button [, OutX, OutY, OutW, OutH]) 20 | * GetButtonState(Button, StateQuerry) 21 | * GetCount() 22 | * GetHiddenButtons() 23 | * Insert(Position [, Options, Label1[=Text]:Icon[(Options)], Label2[=Text]:Icon[(Options)]...]) 24 | * LabelToIndex(Label) 25 | * ModifyButton(Button, State [, Set]) 26 | * ModifyButtonInfo(Button, Property, Value) 27 | * MoveButton(Button, Target) 28 | * OnMessage(CommandID) 29 | * OnNotify(Param [, MenuXPos, MenuYPos, Label, ID, AllowCustom]) 30 | * Reset() 31 | * SetButtonSize(W, H) 32 | * SetDefault([Options, Label1[=Text]:Icon[(Options)], Label2[=Text]:Icon[(Options)]...]) 33 | * SetExStyle(Style) 34 | * SetHotItem(Button) 35 | * SetImageList(IL_Default [, IL_Hot, IL_Pressed, IL_Disabled]) 36 | * SetIndent(Value) 37 | * SetListGap(Value) 38 | * SetMaxTextRows([MaxRows]) 39 | * SetPadding(X, Y) 40 | * SetRows([Rows, AddMore]) 41 | * ToggleStyle(Style) 42 | 43 | ## Presets Methods: 44 | * Presets.Delete(Slot) 45 | * Presets.Export(Slot, [ArrayOut]) 46 | * Presets.Import(Slot, [Options, Label1[=Text]:Icon, Label2[=Text]:Icon, Label3[=Text]:Icon...]) 47 | * Presets.Load(Slot) 48 | * Presets.Save(Slot, Buttons) 49 | 50 | ## Useful Toolbar Styles: 51 | Styles can be applied to Gui command options, e.g.: Gui, Add, Custom, ClassToolbarWindow32 0x0800 0x0100 52 | 53 | * TBSTYLE_FLAT := 0x0800 - Shows separators as bars. 54 | * TBSTYLE_LIST := 0x1000 - Shows buttons text on their side. 55 | * TBSTYLE_TOOLTIPS := 0x0100 - Shows buttons text as tooltips. 56 | * CCS_ADJUSTABLE := 0x0020 - Allows customization by double-click and shift-drag. 57 | * CCS_NODIVIDER := 0x0040 - Removes the separator line above the toolbar. 58 | * CCS_NOPARENTALIGN := 0x0008 - Allows positioning and moving toolbars. 59 | * CCS_NORESIZE := 0x0004 - Allows resizing toolbars. 60 | * CCS_VERT := 0x0080 - Creates a vertical toolbar (add WRAP to button options). 61 | 62 | - - - 63 | 64 | ## Add() 65 | Add button(s) to the end the toolbar. The Buttons parameters sets target Label, text caption and icon index for each button. If not a valid label name, a function name can be used instead (parameters can be passed to the OnMessage method). To add a separator call this method without parameters. Prepend any non letter or digit symbol, such as "-" or "**" to the label to add a hidden button. Hidden buttons won't be visible when Gui is shown but will still be available in the customize window. E.g.: "-Label=New:1", "*Label:2". 66 | 67 | ### Return 68 | TRUE if successful, FALSE if there was a problem. 69 | 70 | ### Parameters: 71 | * **Options** - Enter zero or more words, separated by space or tab, from the following list to set buttons' initial states and styles: Checked, Ellipses, Enabled, Hidden, Indeterminate, Marked, Pressed, Wrap, Button, Sep, Check, Group, CheckGroup, Dropdown, AutoSize, NoPrefix, ShowText, WholeDropdown. You can also set the minimum and maximum button width, for example W20-100 would set min to 20 and max to 100. This option affects all buttons in the toolbar when added or inserted but does not prevent modifying button sizes. If this parameter is blank it defaults to "Enabled", otherwise you must set this parameter to enable buttons. You may pass integer values that correspond to (a combination of) button styles. You cannot set states this way (it will always be set to "Enabled"). 72 | * **Buttons** - Buttons can be added in the following format: Label=Text:1, where "Label" is the target label to execute when the button is pressed, "Text" is caption to be displayed with the button or as a Tooltip if the toolbar has the TBSTYLE_TOOLTIPS style (this parameter can be omitted) and"1" can be any numeric value that represents the icon index in the ImageList (0 means no icon). You can include specific states and styles for a button appending them inside parenthesis after the icon. E.g.: "Label=Text:3(Enabled Dropdown)". This option can also be an Integer value, in this case the general options are ignored for that button. To add a separator between buttons specify "" or equivalent. 73 | 74 | ## AutoSize() 75 | Auto-sizes toolbar. 76 | 77 | ### Return 78 | TRUE if successful, FALSE if there was a problem. 79 | 80 | ## Customize() 81 | Displays the Customize Toolbar dialog box. 82 | 83 | ### Return 84 | TRUE if successful, FALSE if there was a problem. 85 | 86 | ## Delete() 87 | Delete one or all buttons. 88 | 89 | ### Return 90 | TRUE if successful, FALSE if there was a problem. 91 | 92 | ### Parameters 93 | * **Button** - 1-based index of the button. If omitted deletes all buttons. 94 | 95 | ## Export() 96 | Returns a text string with current buttons and order in Add and Insert methods compatible format (this includes button's styles but not states). Duplicate labels are ignored. 97 | 98 | ### Return 99 | A text string with current buttons information to be exported. 100 | 101 | ### Parameters 102 | * **ArrayOut** - Set to TRUE to return an object array. The returned object format is compatible with Presets.Save and Presets.Load methods, which can be used to save and load layout presets. 103 | * **HidMark** - Changes the default symbol to prepend to hidden buttons. 104 | 105 | ## Get() 106 | Retrieves information from the toolbar. 107 | 108 | ### Return 109 | TRUE if successful, FALSE if there was a problem. 110 | 111 | ### Parameters 112 | * **HotItem** - OutputVar to store the 1-based index of current HotItem. 113 | * **TextRows** - OutputVar to store the number of text rows 114 | * **Rows** - OutputVar to store the number of rows for vertical toolbars. 115 | * **BtnWidth** - OutputVar to store the buttons' width in pixels. 116 | * **BtnHeight** - OutputVar to store the buttons' heigth in pixels. 117 | * **Style** - OutputVar to store the current styles numeric value. 118 | * **ExStyle** - OutputVar to store the current extended styles numeric value. 119 | 120 | ## GetButton() 121 | Retrieves information from the toolbar buttons. 122 | 123 | ### Return 124 | TRUE if successful, FALSE if there was a problem. 125 | 126 | ### Parameters 127 | * **Button** - 1-based index of the button. 128 | * **ID** - OutputVar to store the button's command ID. 129 | * **Text** - OutputVar to store the button's text caption. 130 | * **State** - OutputVar to store the button's state numeric value. 131 | * **Style** - OutputVar to store the button's style numeric value. 132 | * **Icon** - OutputVar to store the button's icon index. 133 | * **Label** - OutputVar to store the button's associated script label or function. 134 | * **Index** - OutputVar to store the button's text string index. 135 | 136 | ## GetButtonPos() 137 | Retrieves position and size of a specific button, relative to the toolbar control. 138 | 139 | ### Return 140 | TRUE if successful, FALSE if there was a problem. 141 | 142 | ### Parameters 143 | * **Button** - 1-based index of the button. 144 | * **OutX** - OutputVar to store the button's horizontal position. 145 | * **OutY** - OutputVar to store the button's vertical position. 146 | * **OutW** - OutputVar to store the button's width. 147 | * **OutH** - OutputVar to store the button's height. 148 | 149 | ## GetButtonState() 150 | Retrieves the state of a button based on a querry. 151 | 152 | ### Return 153 | The TRUE if the StateQuerry is true, FALSE if it's not. 154 | 155 | ### Parameters 156 | * **StateQuerry** - Enter one of the following words to get the state of the button** - Checked, Enabled, Hidden, Highlighted, Indeterminate, Pressed. 157 | 158 | ## GetCount() 159 | Retrieves the total number of buttons. 160 | 161 | ### Return 162 | The total number of buttons in the toolbar. 163 | 164 | ## GetHiddenButtons() 165 | Retrieves which buttons are hidden when the toolbar size is smaller then the total size of the buttons it has. This method is most useful when the toolbar is a child window of a Rebar control, in order to show a menu when the chevron is pushed. It does not retrieve buttons hidden by gui size. 166 | 167 | ### Return 168 | An array with all buttons hidden by the Rebar band. Each key in the array has 4 properties: ID, Text, Label and Icon. 169 | 170 | ## Insert() 171 | Insert button(s) in specified postion. To insert a separator call this method without parameters. 172 | 173 | ### Return 174 | TRUE if successful, FALSE if there was a problem. 175 | 176 | ### Parameters 177 | * **Position** - 1-based index of button position to insert the new buttons. 178 | * **Options** - Same as Add(). 179 | * **Buttons** - Same as Add(). 180 | 181 | ## LabelToIndex() 182 | Converts a button label to its index in a toolbar. 183 | 184 | ### Return 185 | The 1-based index for the button or FALSE if Label is invalid. 186 | 187 | ### Parameters 188 | * **Label** - Button's associated label or function. 189 | 190 | ## ModifyButton() 191 | Sets button states. 192 | 193 | ### Return 194 | TRUE if successful, FALSE if there was a problem. 195 | 196 | ### Parameters 197 | * **Button** - 1-based index of the button. 198 | * **State** - Enter one word from the follwing list to change a button's state** - Check, Enable, Hide, Mark, Press. 199 | * **Set** - Enter TRUE or FALSE to set the state on/off. 200 | 201 | ## ModifyButtonInfo() 202 | Sets button parameters such as Icon and CommandID. 203 | 204 | ### Return 205 | TRUE if successful, FALSE if there was a problem. 206 | 207 | ### Parameters 208 | * **Button** - 1-based index of the button. 209 | * **Property** - Enter one word from the following list to select the Property to be set** - Command, Image, Size, State, Style, Text, Label. 210 | * **Value** - The value to be set in the selected Property. If Property is State or Style you can enter named values as in the Add options. 211 | 212 | ## MoveButton() 213 | Moves a toolbar button (change order). 214 | 215 | ### Return 216 | TRUE if successful, FALSE if there was a problem. 217 | 218 | ### Parameters 219 | * **Button** - 1-based index of the button to be moved. 220 | * **Target** - 1-based index of the new position. 221 | 222 | ## OnMessage() 223 | Run label associated with button's Command identifier. This method should be called from a function monitoring the WM_COMMAND message. Pass the wParam as the CommandID. 224 | 225 | ### Return 226 | TRUE if target label or function exists, or FALSE otherwise. 227 | 228 | ### Parameters 229 | * **CommandID** - Command ID associated with the button. This is send via WM_COMMAND message, you must pass the wParam from inside a function that monitors this message. 230 | * **FuncParams** - In case the button is associated with a valid function, you may pass optional parameters for the function call. You can pass any number of parameters. 231 | 232 | ## OnNotify() 233 | Handles toolbar notifications. This method should be called from a function monitoring the WM_NOTIFY message. Pass the lParam as the Param. The returned value should be used as return value for the monitoring function as well. 234 | 235 | ### Return 236 | The required return value for the function monitoring the the WM_NOTIFY message. 237 | 238 | ### Parameters 239 | * **Param** - The lParam from WM_NOTIFY message. 240 | * **MenuXPos** - OutputVar to store the horizontal position for a menu. 241 | * **MenuYPos** - OutputVar to store the vertical position for a menu. 242 | * **BtnLabel** - OutputVar to store the label or function name associated with the button. 243 | * **ID** - OutputVar to store the button's Command ID. 244 | * **AllowCustom** - Set to FALSE to prevent customization of toolbars. 245 | * **AllowReset** - Set to FALSE to prevent Reset button from restoring original buttons. 246 | * **HideHelp** - Set to FALSE to show the Help button in the customize dialog. 247 | 248 | ## Reset() 249 | Restores all toolbar's buttons to default layout. Default layout is set by the buttons added. This can be changed calling the SetDefault method. 250 | 251 | ### Return 252 | TRUE if successful, FALSE if there was a problem. 253 | 254 | ## SetButtonSize() 255 | Sets the size of buttons on a toolbar. Affects current buttons. 256 | 257 | ### Return 258 | TRUE if successful, FALSE if there was a problem. 259 | 260 | ### Parameters 261 | * **W** - Width of buttons, in pixels 262 | * **H** - Height of buttons, in pixels 263 | 264 | ## SetDefault() 265 | Sets the internal default layout to be used when customizing or when the Reset method is called. 266 | 267 | ### Return 268 | Always TRUE. 269 | 270 | ### Parameters 271 | * **Options** - Same as Add(). 272 | * **Buttons** - Same as Add(). 273 | 274 | -------------------------------------------------------------------------------- /Examples/Toolbar_Demo.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv 2 | #SingleInstance, Force 3 | SetBatchLines, -1 4 | Process, Priority,, High 5 | #Include ..\Class_Toolbar.ahk 6 | 7 | ; Icons from Win7 (change them for other OS's). 8 | ; Create 2 Default ImageLists for the first Toolbar (small and large). 9 | Loop, 2 10 | { 11 | ILA%A_Index% := IL_Create(11, 2, A_Index-1) 12 | IL_Add(ILA%A_Index%, "imageres.dll", 3) ; 1: New 13 | IL_Add(ILA%A_Index%, "shell32.dll", 46) ; 2: Open 14 | IL_Add(ILA%A_Index%, "shell32.dll", 259) ; 3: Save 15 | IL_Add(ILA%A_Index%, "shell32.dll", 260) ; 4: Cut 16 | IL_Add(ILA%A_Index%, "shell32.dll", 135) ; 5: Copy 17 | IL_Add(ILA%A_Index%, "shell32.dll", 261) ; 6: Paste 18 | IL_Add(ILA%A_Index%, "shell32.dll", 304) ; 7: Toggle Icons 19 | IL_Add(ILA%A_Index%, "shell32.dll", 300) ; 8: Toggle View 20 | IL_Add(ILA%A_Index%, "shell32.dll", 44) ; 9: Insert button 21 | IL_Add(ILA%A_Index%, "shell32.dll", 132) ; 10: Delete button 22 | IL_Add(ILA%A_Index%, "shell32.dll", 1) ; 11: Empty Icon 23 | } 24 | 25 | ; Create Default ImageList for the second Toolbar with large icons. 26 | ILB := IL_Create(5, 2, True) 27 | IL_Add(ILB, "explorer.exe", 1) ; 1: Windows Explorer 28 | IL_Add(ILB, "notepad.exe", 1) ; 2: Notepad 29 | IL_Add(ILB, "calc.exe", 1) ; 3: Calculator 30 | IL_Add(ILB, "mspaint.exe", 1) ; 4: Paint 31 | IL_Add(ILB, "cmd.exe", 1) ; 5: Command Prompt 32 | 33 | ; Create Hot ImageList for the second Toolbar with large icons. 34 | ILBH := IL_Create(5, 2, True) 35 | IL_Add(ILBH, "explorer.exe", 2) ; 1: Windows Explorer 36 | IL_Add(ILBH, "explorer.exe", 4) ; 2: Notepad 37 | IL_Add(ILBH, "explorer.exe", 11) ; 3: Calculator 38 | IL_Add(ILBH, "mspaint.exe", 2) ; 4: Paint 39 | IL_Add(ILBH, "cmd.exe", 1) ; 5: Command Prompt 40 | 41 | ; Create Pressed ImageList for the second Toolbar with large icons. 42 | ILBP := IL_Create(5, 2, True) 43 | Loop, 5 44 | IL_Add(ILBP, "explorer.exe", 8) 45 | 46 | ; Presets menu: 47 | Loop, 5 48 | { 49 | Menu, SaveMenu, Add, Slot %A_Index%, SaveLayout 50 | Menu, LoadMenu, Add, Slot %A_Index%, LoadLayout 51 | Menu, LoadMenu, Disable, Slot %A_Index% 52 | } 53 | Menu, PresetsMenu, Add, Save, :SaveMenu 54 | Menu, PresetsMenu, Add, Load, :LoadMenu 55 | Menu, PresetsMenu, Add, Clear, ClearPresets 56 | Menu, Presets, Add, Presets, :PresetsMenu 57 | Menu, Customize, Add, Customize Upper, Customize1 58 | Menu, Customize, Add, Customize Side, Customize2 59 | Menu, Presets, Add, Customize , :Customize 60 | Gui, Menu, Presets 61 | 62 | Gui, +hwndTestGui 63 | Gui, Add, Text, x2 y60, Tests: 64 | Gui, Add, Button, Section x+10 yp gTests, Enable 65 | Gui, Add, Button, x+5 yp gTests, Check 66 | Gui, Add, Button, x+5 yp gTests, Mark 67 | Gui, Add, Button, x+5 yp gTests, Press 68 | Gui, Add, Button, x+5 yp gTests, Hide 69 | Gui, Add, Button, x+5 yp gChangeImage, Change Icon 70 | Gui, Add, Button, x+5 yp gChangeText, Change Caption 71 | Gui, Add, Button, x+5 yp gMoveB vMoveB, Move 72 | Gui, Add, Text, x+5 yp+5, (SHIFT + Drag buttons or Double-Click a toolbar to customize it) 73 | Gui, Add, Button, xs y+5 gHotItem, HotItem 74 | Gui, Add, Button, x+5 yp gChangeSize, Change Size 75 | Gui, Add, Button, x+5 yp gIndent, Indent 76 | Gui, Add, Button, x+5 yp gGap, Gap 77 | Gui, Add, Button, x+5 yp gPadding, Padding 78 | Gui, Add, Button, x+5 yp gGetInfo, Get Info 79 | Gui, Add, Button, x+5 yp gGetButtonInfo, Get Button Info 80 | Gui, Add, Text, x+5 yp+5, (Click the Save button to save toolbars layouts and presets) 81 | Gui, Add, Edit, x2 y+10 w750 r36 hwndTextEdit 82 | 83 | ; TBSTYLE_FLAT := 0x0800 Required to show separators as bars. 84 | ; TBSTYLE_TOOLTIPS := 0x0100 Required to show Tooltips. 85 | ; CCS_ADJUSTABLE := 0x0020 Required to allow customization by double-click and shift-drag. 86 | ; CCS_NODIVIDER := 0x0040 Removes the separator line above the toolbar. 87 | Gui, Add, Custom, ClassToolbarWindow32 hwndTopBar vTop 0x0800 0x0100 0x0020 0x0040 88 | ; CCS_VERT := 0x0080 Required for correct height of vertical toolbars. 89 | ; CCS_NOPARENTALIGN := 0x0008 Required tow allow positioning of toolbar. 90 | ; CCS_NORESIZE := 0x0004 Required tow allow resizing of toolbar. 91 | Gui, Add, Custom, ClassToolbarWindow32 hwndSideBar x760 y110 w50 h400 vSide 0x0800 0x0100 0x0020 0x0080 0x0040 0x0008 0x0004 92 | 93 | ; Check for saved button positions and presets in INI file. 94 | IniRead, TopButtons, tbPosInfo.ini, ToolbarButtons, TopButtons 95 | IniRead, SideButtons, tbPosInfo.ini, ToolbarButtons, SideButtons 96 | Loop, 5 97 | IniRead, Preset%A_Index%, tbPosInfo.ini, ToolbarPresets, TopPresets%A_Index% 98 | 99 | ; Methods should be called after Gui, Show or they might fail eventually. 100 | Gui, Show, w800 h600, [Class] Toolbar - Demostration Script 101 | 102 | ; Initialize Toolbars. 103 | TB1 := New Toolbar(TopBar) 104 | 105 | ; Set ImageLists. 106 | TB1.SetImageList(ILA1) 107 | 108 | BtnsArray := [] 109 | 110 | ; Define default buttons. 111 | DefArray1 := [ "New=New:1", "Open=Open:2(Enabled Dropdown)", "Save=Save:3(Enabled Dropdown)" 112 | , "", "Cut=Cut:4", "Copy=Copy:5", "Paste=Paste:6" 113 | , "", "ToggleIcons=Icons:7", "ToggleStyle=View:8" 114 | , "", "Insert=Insert:9", "Delete=Delete:10" ] 115 | If (TopButtons = "ERROR") ; If no INI file found, use default. 116 | BtnsArray := DefArray1 117 | Else 118 | Loop, Parse, TopButtons, `,, %A_Space% 119 | BtnsArray[A_Index] := A_LoopField 120 | 121 | ; Add buttons. 122 | TB1.Add("", BtnsArray*) ; The * passes the whole array as a variadic parameter. 123 | 124 | ; Removes text labels and show them as tooltips. 125 | TB1.SetMaxTextRows(0) 126 | 127 | ; Draw arrows in Dropdown style buttons. 128 | TB1.SetExStyle("DrawDDArrows") 129 | 130 | ; Set default buttons. 131 | ; If this is not done reset would set the layout loaded from the INI. 132 | TB1.SetDefault("", DefArray1*) 133 | 134 | ; Load presets. 135 | Loop, 5 136 | { 137 | If (Preset%A_Index% <> "ERROR") && (Preset%A_Index% <> "") 138 | { 139 | PresetArray := [] 140 | Loop, Parse, Preset%A_Index%, `,, %A_Space% 141 | PresetArray[A_Index] := A_LoopField 142 | TB1.Presets.Import(A_Index, "", PresetArray*) 143 | Menu, LoadMenu, Enable, Slot %A_Index% 144 | } 145 | } 146 | 147 | TB2 := New Toolbar(SideBar) 148 | 149 | ; Side toolbar will show different buttons when hovered (hot) or pressed. 150 | TB2.SetImageList(ILB, ILBH, ILBP) 151 | 152 | BtnsArray := [] 153 | 154 | ; The Cmd label has a "-" and will be hidden on start, but available in customize dialog. 155 | DefArray2 := [ "Explorer:1", "Notepad:2", "Calc:3", "", "msPaint:4", "Cmd:5" ] 156 | 157 | If (SideButtons = "ERROR") 158 | BtnsArray := DefArray2 159 | Else 160 | Loop, Parse, SideButtons, `,, %A_Space% 161 | BtnsArray[A_Index] := A_LoopField 162 | 163 | TB2.Add("Enabled Wrap", BtnsArray*) 164 | 165 | TB2.SetDefault("Enabled Wrap", DefArray2*) 166 | 167 | ; Set a function to monitor the Toolbar's messages. 168 | WM_COMMAND := 0x111 169 | OnMessage(WM_COMMAND, "TB_Messages") 170 | 171 | ; Set a function to monitor notifications. 172 | WM_NOTIFY := 0x4E 173 | OnMessage(WM_NOTIFY, "TB_Notify") 174 | 175 | return 176 | 177 | ; This function will receive the messages sent by both Toolbar's buttons. 178 | TB_Messages(wParam, lParam) 179 | { 180 | Global ; Function (or at least the Handles) must be global. 181 | TB1.OnMessage(wParam) ; Handles messages from TB1 182 | TB2.OnMessage(wParam) ; Handles messages from TB2 183 | } 184 | 185 | ; This function will receive the notifications. 186 | TB_Notify(wParam, lParam) 187 | { 188 | Global TB1, TB2 ; Function (or at least the Handles) must be global. 189 | ReturnCode := TB1.OnNotify(lParam, MX, MY, Label, ID) ; Handles notifications. 190 | If (ReturnCode = "") ; Check if previous return was blank to know if you should call OnNotify for the next. 191 | ReturnCode := TB2.OnNotify(lParam) ; The return value contains the required 192 | If (Label) ; return for the call, so it must be 193 | ShowMenu(Label, MX, MY) ; passed as return parameter. 194 | return ReturnCode 195 | } 196 | 197 | ; This is a method to show a menu using the values returned from OnNotify method. 198 | ; You can also use GoSub if the function or the variables used are global. 199 | ShowMenu(Menu, X, Y) 200 | { 201 | Menu, TestMenu, Add, %Menu% As, %Menu% 202 | Menu, TestMenu, Show, %X%, %Y% 203 | Menu, TestMenu, DeleteAll 204 | } 205 | 206 | #If WinActive("ahk_id " TestGui) 207 | 208 | SaveLayout: 209 | Preset := TB1.Export(True) 210 | If (TB1.Presets.Save(A_ThisMenuItemPos, Preset)) 211 | { 212 | Menu, LoadMenu, Enable, Slot %A_ThisMenuItemPos% 213 | GuiControl,, %TextEdit%, Upper Toolbar preset saved to Slot %A_ThisMenuItemPos% 214 | } 215 | return 216 | 217 | LoadLayout: 218 | TB1.Presets.Load(A_ThisMenuItemPos) 219 | return 220 | 221 | ClearPresets: 222 | Loop, 5 223 | { 224 | TB1.Presets.Delete(A_Index) 225 | Menu, LoadMenu, Disable, Slot %A_Index% 226 | } 227 | return 228 | 229 | Tests: 230 | OnOff := !OnOff 231 | TB1.ModifyButton(12, A_GuiControl, OnOff) 232 | return 233 | 234 | ChangeImage: 235 | ImageN++ 236 | If (ImageN > 11) 237 | ImageN := 1 238 | TB1.ModifyButtonInfo(12, "Image", ImageN) 239 | return 240 | 241 | ChangeText: 242 | Loop, % TB1.GetCount() 243 | TB1.ModifyButtonInfo(A_Index, "Text", "Label " A_Index) 244 | return 245 | 246 | ChangeSize: 247 | nSize := (n := !n) ? 40 : 20 248 | TB1.SetButtonSize(nSize, nSize) 249 | TB1.AutoSize() 250 | return 251 | 252 | HotItem: 253 | hItem++ 254 | If (hItem > TB1.GetCount()) 255 | hItem := 1 256 | TB1.SetHotItem(hItem) 257 | return 258 | 259 | Indent: 260 | TB1.SetIndent((tInd := !tInd) ? 50 : 0) 261 | return 262 | 263 | Gap: 264 | TB1.SetListGap((tGap := !tGap) ? 10 : 0) 265 | return 266 | 267 | Padding: 268 | TB1.SetPadding(50, 50) 269 | return 270 | 271 | MoveB: 272 | TB1.MoveButton(12, 13) 273 | return 274 | 275 | F5:: 276 | GetInfo: 277 | TB1.Get(hItemA, TxRowsA, RowsA, WidthA, HeightA, StyleA, ExStyleA) 278 | TB2.Get(hItemB, TxRowsB, RowsB, WidthB, HeightB, StyleB, ExStyleB) 279 | GuiControl,, %TextEdit%, % "Upper toolbar info:" 280 | . "`n`tButtons: " TB1.GetCount() 281 | . "`n`tHotItem: " hItemA 282 | . "`n`tText Rows: " TxRowsA 283 | . "`n`tRows: " RowsA 284 | . "`n`tButtons Size: " WidthA " x " HeightA 285 | . "`n`tStyle: " StyleA 286 | . "`n`tExStyle: " ExStyleA 287 | . "`n`nSide toolbar info:" 288 | . "`n`tButtons: " TB2.GetCount() 289 | . "`n`tHotItem: " hItemB 290 | . "`n`tText Rows: " TxRowsB 291 | . "`n`tRows: " RowsB 292 | . "`n`tButtons Size: " WidthB " x " HeightB 293 | . "`n`tStyle: " StyleB 294 | . "`n`tExStyle: " ExStyleB 295 | return 296 | 297 | F6:: 298 | GetButtonInfo: 299 | AllBtnInfo := "Upper Toolbar:`n" 300 | Loop, % TB1.GetCount() 301 | { 302 | TB1.GetButton(A_Index, IDA, TextA, StateA, StyleA, IconA, LabelA) 303 | AllBtnInfo .= "Button " A_Index " info:" 304 | . "`n`tCommand ID: " IDA 305 | . "`n`tText Caption: " TextA 306 | . "`n`tState: " StateA 307 | . "`n`tStyle: " StyleA 308 | . "`n`tIcon Index: " IconA 309 | . "`n`tLabel: " LabelA "`n`n" 310 | } 311 | AllBtnInfo .= "`nSide Toolbar:`n" 312 | Loop, % TB2.GetCount() 313 | { 314 | TB2.GetButton(A_Index, IDA, TextA, StateA, StyleA, IconA, LabelA) 315 | AllBtnInfo .= "Button " A_Index " info:" 316 | . "`n`tCommand ID: " IDA 317 | . "`n`tText Caption: " TextA 318 | . "`n`tState: " StateA 319 | . "`n`tStyle: " StyleA 320 | . "`n`tIcon Index: " IconA 321 | . "`n`tLabel: " LabelA "`n`n" 322 | } 323 | GuiControl,, %TextEdit%, % AllBtnInfo 324 | return 325 | 326 | New: 327 | GuiControl,, %TextEdit% 328 | Gui, Show,, [Class] Toolbar - Demostration Script 329 | return 330 | 331 | Open: 332 | Gui, +OwnDialogs 333 | FileSelectFile, TextFile, 3 334 | If !TextFile 335 | return 336 | FileRead, InText, %TextFile% 337 | GuiControl,, %TextEdit%, %InText% 338 | Gui, Show,, [Class] Toolbar - Demostration Script 339 | return 340 | 341 | Save: 342 | ; Save toolbars current buttons. 343 | Buttons1 := TB1.Export(), Buttons2 := TB2.Export() 344 | IniWrite, %Buttons1%, tbPosInfo.ini, ToolbarButtons, TopButtons 345 | IniWrite, %Buttons2%, tbPosInfo.ini, ToolbarButtons, SideButtons 346 | Loop, 5 ; Save Upper toolbar presets. 347 | IniWrite, % TB1.Presets.Export(A_Index), tbPosInfo.ini, ToolbarPresets, TopPresets%A_Index% 348 | Gui, Show,, Saved Toolbars layouts and presets to "%A_ScriptDir%\tbPosInfo.ini" 349 | return 350 | 351 | Cut: 352 | GuiControl, Focus, %TextEdit% 353 | ControlSend,, {Control Down}{x}{Control Up}, ahk_id %TextEdit% 354 | return 355 | 356 | Copy: 357 | GuiControl, Focus, %TextEdit% 358 | ControlSend,, {Control Down}{c}{Control Up}, ahk_id %TextEdit% 359 | return 360 | 361 | Paste: 362 | GuiControl, Focus, %TextEdit% 363 | ControlSend,, {Control Down}{v}{Control Up}, ahk_id %TextEdit% 364 | return 365 | 366 | ToggleIcons: 367 | View := "ILA" ((LargeView := !LargeView) ? 2 : 1) 368 | TB1.SetImageList(%View%) 369 | TB1.AutoSize() 370 | return 371 | 372 | ToggleStyle: 373 | TB1.ToggleStyle("List") 374 | TB1.SetMaxTextRows(isList := !isList ? 1 : 0) 375 | TB1.AutoSize() 376 | return 377 | 378 | Insert: 379 | TB1.Insert(14, "", "Null=Null:11") 380 | return 381 | 382 | Delete: 383 | TB1.Delete(14) 384 | return 385 | 386 | Null: 387 | Gui, +OwnDialogs 388 | MsgBox, This button does nothing! 389 | return 390 | 391 | Explorer: 392 | Notepad: 393 | Calc: 394 | msPaint: 395 | Cmd: 396 | Run, %A_ThisLabel% 397 | return 398 | 399 | Customize1: 400 | TB1.Customize() 401 | return 402 | 403 | Customize2: 404 | TB2.Customize() 405 | return 406 | 407 | GuiClose: 408 | ExitApp 409 | -------------------------------------------------------------------------------- /Class_Toolbar.ahk: -------------------------------------------------------------------------------- 1 | ;======================================================================================= 2 | ; 3 | ; Class Toolbar 4 | ; 5 | ; Author: Pulover [Rodolfo U. Batista] 6 | ; AHK version: 1.1.23.01 7 | ; 8 | ; Class for AutoHotkey Toolbar custom controls 9 | ;======================================================================================= 10 | ; 11 | ; This class provides intuitive methods to work with Toolbar controls created via 12 | ; Gui, Add, Custom, ClassToolbarWindow32. 13 | ; 14 | ; Note: It's recommended to call any method only after Gui, Show. Adding or modifying 15 | ; buttons of a toolbar in a Gui that is not yet visible might fail eventually. 16 | ; 17 | ;======================================================================================= 18 | ; 19 | ; Toolbar Methods: 20 | ; Add([Options, Label1[=Text]:Icon[(Options)], Label2[=Text]:Icon[(Options)]...]) 21 | ; AutoSize() 22 | ; Customize() 23 | ; Delete(Button) 24 | ; Export() 25 | ; Get([HotItem, TextRows, Rows, BtnWidth, BtnHeight, Style, ExStyle]) 26 | ; GetButton(Button [, ID, Text, State, Style, Icon, Label, Index]) 27 | ; GetButtonPos(Button [, OutX, OutY, OutW, OutH]) 28 | ; GetButtonState(Button, StateQuerry) 29 | ; GetCount() 30 | ; GetHiddenButtons() 31 | ; Insert(Position [, Options, Label1[=Text]:Icon[(Options)], Label2[=Text]:Icon[(Options)]...]) 32 | ; LabelToIndex(Label) 33 | ; ModifyButton(Button, State [, Set]) 34 | ; ModifyButtonInfo(Button, Property, Value) 35 | ; MoveButton(Button, Target) 36 | ; OnMessage(CommandID) 37 | ; OnNotify(Param [, MenuXPos, MenuYPos, Label, ID, AllowCustom]) 38 | ; Reset() 39 | ; SetButtonSize(W, H) 40 | ; SetDefault([Options, Label1[=Text]:Icon[(Options)], Label2[=Text]:Icon[(Options)]...]) 41 | ; SetExStyle(Style) 42 | ; SetHotItem(Button) 43 | ; SetImageList(IL_Default [, IL_Hot, IL_Pressed, IL_Disabled]) 44 | ; SetIndent(Value) 45 | ; SetListGap(Value) 46 | ; SetMaxTextRows([MaxRows]) 47 | ; SetPadding(X, Y) 48 | ; SetRows([Rows, AddMore]) 49 | ; ToggleStyle(Style) 50 | ; 51 | ; Presets Methods: 52 | ; Presets.Delete(Slot) 53 | ; Presets.Export(Slot, [ArrayOut]) 54 | ; Presets.Import(Slot, [Options, Label1[=Text]:Icon, Label2[=Text]:Icon, Label3[=Text]:Icon...]) 55 | ; Presets.Load(Slot) 56 | ; Presets.Save(Slot, Buttons) 57 | ; 58 | ;======================================================================================= 59 | ; 60 | ; Useful Toolbar Styles: Styles can be applied to Gui command options, e.g.: 61 | ; Gui, Add, Custom, ClassToolbarWindow32 0x0800 0x0100 62 | ; 63 | ; TBSTYLE_FLAT := 0x0800 - Shows separators as bars. 64 | ; TBSTYLE_LIST := 0x1000 - Shows buttons text on their side. 65 | ; TBSTYLE_TOOLTIPS := 0x0100 - Shows buttons text as tooltips. 66 | ; CCS_ADJUSTABLE := 0x0020 - Allows customization by double-click and shift-drag. 67 | ; CCS_NODIVIDER := 0x0040 - Removes the separator line above the toolbar. 68 | ; CCS_NOPARENTALIGN := 0x0008 - Allows positioning and moving toolbars. 69 | ; CCS_NORESIZE := 0x0004 - Allows resizing toolbars. 70 | ; CCS_VERT := 0x0080 - Creates a vertical toolbar (add WRAP to button options). 71 | ; 72 | ;======================================================================================= 73 | Class Toolbar extends Toolbar.Private 74 | { 75 | ;======================================================================================= 76 | ; Method: Add 77 | ; Description: Add button(s) to the end the toolbar. The Buttons parameters 78 | ; sets target Label, text caption and icon index for each 79 | ; button. If not a valid label name, a function name can be 80 | ; used instead. 81 | ; To add a separator call this method without parameters. 82 | ; Prepend any non letter or digit symbol, such as "-" or "*" 83 | ; to the label to add a hidden button. Hidden buttons won't 84 | ; be visible when Gui is shown but will still be available 85 | ; in the customize window. E.g.: "-Label=New:1", "*Label:2". 86 | ; Parameters: 87 | ; Options: Enter zero or more words, separated by space or tab, from the 88 | ; following list to set buttons' initial states and styles: 89 | ; Checked, Ellipses, Enabled, Hidden, Indeterminate, Marked, 90 | ; Pressed, Wrap, Button, Sep, Check, Group, CheckGroup, 91 | ; Dropdown, AutoSize, NoPrefix, ShowText, WholeDropdown. 92 | ; You can also set the minimum and maximum button width, 93 | ; for example W20-100 would set min to 20 and max to 100. 94 | ; This option affects all buttons in the toolbar when added or 95 | ; inserted but does not prevent modifying button sizes. 96 | ; If this parameter is blank it defaults to "Enabled", otherwise 97 | ; you must set this parameter to enable buttons. 98 | ; You may pass integer values that correspond to (a combination of) 99 | ; button styles. You cannot set states this way (it will always 100 | ; be set to "Enabled"). 101 | ; Buttons: Buttons can be added in the following format: Label=Text:1, 102 | ; where "Label" is the target label to execute when the 103 | ; button is pressed, "Text" is caption to be displayed 104 | ; with the button or as a Tooltip if the toolbar has the 105 | ; TBSTYLE_TOOLTIPS style (this parameter can be omitted) and 106 | ; "1" can be any numeric value that represents the icon index 107 | ; in the ImageList (0 means no icon). 108 | ; You can include specific states and styles for a button appending 109 | ; them inside parenthesis after the icon. E.g.: 110 | ; "Label=Text:3(Enabled Dropdown)". This option can also be 111 | ; an Integer value, in this case the general options are 112 | ; ignored for that button. 113 | ; To add a separator between buttons specify "" or equivalent. 114 | ; Return: TRUE if successful, FALSE if there was a problem. 115 | ;======================================================================================= 116 | Add(Options := "Enabled", Buttons*) 117 | { 118 | If (!Buttons.Length()) 119 | { 120 | Struct := this.BtnSep(TBBUTTON, Options), this.DefaultBtnInfo.Push(Struct) 121 | SendMessage, this.TB_ADDBUTTONS, 1, &TBBUTTON,, % "ahk_id " this.tbHwnd 122 | If (ErrorLevel = "FAIL") 123 | return false 124 | } 125 | Else If (Options = "") 126 | Options := "Enabled" 127 | For each, Button in Buttons 128 | { 129 | If !(this.SendMessage(Button, Options, this.TB_ADDBUTTONS, 1)) 130 | return false 131 | } 132 | this.AutoSize() 133 | return true 134 | } 135 | ;======================================================================================= 136 | ; Method: AutoSize 137 | ; Description: Auto-sizes toolbar. 138 | ; Return: TRUE if successful, FALSE if there was a problem. 139 | ;======================================================================================= 140 | AutoSize() 141 | { 142 | PostMessage, this.TB_AUTOSIZE, 0, 0,, % "ahk_id " this.tbHwnd 143 | return ErrorLevel ? false : true 144 | } 145 | ;======================================================================================= 146 | ; Method: Customize 147 | ; Description: Displays the Customize Toolbar dialog box. 148 | ; Return: TRUE if successful, FALSE if there was a problem. 149 | ;======================================================================================= 150 | Customize() 151 | { 152 | SendMessage, this.TB_CUSTOMIZE, 0, 0,, % "ahk_id " this.tbHwnd 153 | return (ErrorLevel = "FAIL") ? false : true 154 | } 155 | ;======================================================================================= 156 | ; Method: Delete 157 | ; Description: Delete one or all buttons. 158 | ; Parameters: 159 | ; Button: 1-based index of the button. If omitted deletes all buttons. 160 | ; Return: TRUE if successful, FALSE if there was a problem. 161 | ;======================================================================================= 162 | Delete(Button := "") 163 | { 164 | If (!Button) 165 | { 166 | Loop, % this.GetCount() 167 | this.Delete(1) 168 | } 169 | Else 170 | SendMessage, this.TB_DELETEBUTTON, Button-1, 0,, % "ahk_id " this.tbHwnd 171 | return (ErrorLevel = "FAIL") ? false : true 172 | } 173 | ;======================================================================================= 174 | ; Method: Export() 175 | ; Description: Returns a text string with current buttons and order in Add and 176 | ; Insert methods compatible format (this includes button's 177 | ; styles but not states). Duplicate labels are ignored. 178 | ; Parameters: 179 | ; ArrayOut: Set to TRUE to return an object array. The returned object 180 | ; format is compatible with Presets.Save and Presets.Load 181 | ; methods, which can be used to save and load layout presets. 182 | ; HidMark: Changes the default symbol to prepend to hidden buttons. 183 | ; Return: A text string with current buttons information to be exported. 184 | ;======================================================================================= 185 | Export(ArrayOut := false, HidMark := "-") 186 | { 187 | BtnArray := [], IncLabels := ":" 188 | Loop, % this.GetCount() 189 | { 190 | this.GetButton(A_Index, ID, Text, State, Style, Icon) 191 | , Label := this.Labels[ID], IncLabels .= Label ":" 192 | , cString := (Label ? (Label (Text ? "=" Text : "") 193 | . ":" Icon (Style ? "(" Style ")" : "")) : "") ", " 194 | , BtnString .= cString 195 | If (ArrayOut) 196 | BtnArray.Push({Icon: Icon-1, ID: ID, State: State 197 | , Style: Style, Text: Text, Label: Label}) 198 | } 199 | For i, Button in this.DefaultBtnInfo 200 | { 201 | If (!InStr(IncLabels, ":" (Label := this.Labels[Button.ID]) ":")) 202 | { 203 | If (!Label) 204 | continue 205 | oString := Label (Button.Text ? "=" Button.Text : "") 206 | . ":" Button.Icon+1 (Button.Style ? "(" Button.Style ")" : "") 207 | BtnString .= HidMark oString ", " 208 | } 209 | } 210 | return ArrayOut ? BtnArray : RTrim(BtnString, ", ") 211 | } 212 | ;======================================================================================= 213 | ; Method: Get 214 | ; Description: Retrieves information from the toolbar. 215 | ; Parameters: 216 | ; HotItem: OutputVar to store the 1-based index of current HotItem. 217 | ; TextRows: OutputVar to store the number of text rows 218 | ; Rows: OutputVar to store the number of rows for vertical toolbars. 219 | ; BtnWidth: OutputVar to store the buttons' width in pixels. 220 | ; BtnHeight: OutputVar to store the buttons' heigth in pixels. 221 | ; Style: OutputVar to store the current styles numeric value. 222 | ; ExStyle: OutputVar to store the current extended styles numeric value. 223 | ; Return: TRUE if successful, FALSE if there was a problem. 224 | ;======================================================================================= 225 | Get(ByRef HotItem := "", ByRef TextRows := "", ByRef Rows := "" 226 | , ByRef BtnWidth := "", ByRef BtnHeight := "", ByRef Style := "", ByRef ExStyle := "") 227 | { 228 | SendMessage, this.TB_GETHOTITEM, 0, 0,, % "ahk_id " this.tbHwnd 229 | HotItem := (ErrorLevel = 4294967295) ? 0 : ErrorLevel+1 230 | SendMessage, this.TB_GETTEXTROWS, 0, 0,, % "ahk_id " this.tbHwnd 231 | TextRows := ErrorLevel 232 | SendMessage, this.TB_GETROWS, 0, 0,, % "ahk_id " this.tbHwnd 233 | Rows := ErrorLevel 234 | SendMessage, this.TB_GETBUTTONSIZE, 0, 0,, % "ahk_id " this.tbHwnd 235 | this.MakeShort(ErrorLevel, BtnWidth, BtnHeight) 236 | SendMessage, this.TB_GETSTYLE, 0, 0,, % "ahk_id " this.tbHwnd 237 | Style := ErrorLevel 238 | SendMessage, this.TB_GETEXTENDEDSTYLE, 0, 0,, % "ahk_id " this.tbHwnd 239 | ExStyle := ErrorLevel 240 | return (ErrorLevel = "FAIL") ? false : true 241 | } 242 | ;======================================================================================= 243 | ; Method: GetButton 244 | ; Description: Retrieves information from the toolbar buttons. 245 | ; Parameters: 246 | ; Button: 1-based index of the button. 247 | ; ID: OutputVar to store the button's command ID. 248 | ; Text: OutputVar to store the button's text caption. 249 | ; State: OutputVar to store the button's state numeric value. 250 | ; Style: OutputVar to store the button's style numeric value. 251 | ; Icon: OutputVar to store the button's icon index. 252 | ; Label: OutputVar to store the button's associated script label or function. 253 | ; Index: OutputVar to store the button's text string index. 254 | ; Return: TRUE if successful, FALSE if there was a problem. 255 | ;======================================================================================= 256 | GetButton(Button, ByRef ID := "", ByRef Text := "", ByRef State := "", ByRef Style := "" 257 | , ByRef Icon := "", ByRef Label := "", ByRef Index := "") 258 | { 259 | VarSetCapacity(BtnVar, 8 + (A_PtrSize * 3), 0) 260 | SendMessage, this.TB_GETBUTTON, Button-1, &BtnVar,, % "ahk_id " this.tbHwnd 261 | ID := NumGet(&BtnVar, 4, "Int"), Icon := NumGet(&BtnVar, 0, "Int")+1 262 | , State := NumGet(&BtnVar, 8, "Char"), Style := NumGet(&BtnVar, 9, "Char") 263 | , Index := NumGet(&BtnVar, 8 + (A_PtrSize * 2), "Int"), Label := this.Labels[ID] 264 | SendMessage, this.TB_GETBUTTONTEXT, ID, 0,, % "ahk_id " this.tbHwnd 265 | VarSetCapacity(Buffer, ErrorLevel * (A_IsUnicode ? 2 : 1), 0) 266 | SendMessage, this.TB_GETBUTTONTEXT, ID, &Buffer,, % "ahk_id " this.tbHwnd 267 | Text := StrGet(&Buffer) 268 | return (ErrorLevel = "FAIL") ? false : true 269 | ; Alternative way to retrieve the button state. 270 | ; SendMessage, this.TB_GETSTATE, ID, 0,, % "ahk_id " this.tbHwnd 271 | ; State := ErrorLevel 272 | } 273 | ;======================================================================================= 274 | ; Method: GetButtonPos 275 | ; Description: Retrieves position and size of a specific button, relative to 276 | ; the toolbar control. 277 | ; Parameters: 278 | ; Button: 1-based index of the button. 279 | ; OutX: OutputVar to store the button's horizontal position. 280 | ; OutY: OutputVar to store the button's vertical position. 281 | ; OutW: OutputVar to store the button's width. 282 | ; OutH: OutputVar to store the button's height. 283 | ; Return: TRUE if successful, FALSE if there was a problem. 284 | ;======================================================================================= 285 | GetButtonPos(Button, ByRef OutX := "", ByRef OutY := "", ByRef OutW := "", ByRef OutH := "") 286 | { 287 | this.GetButton(Button, BtnID), VarSetCapacity(RECT, 16, 0) 288 | SendMessage, this.TB_GETRECT, BtnID, &RECT,, % "ahk_id " this.tbHwnd 289 | OutX := NumGet(&RECT, 0, "Int"), OutY := NumGet(&RECT, 4, "Int") 290 | , OutW := NumGet(&RECT, 8, "Int") - OutX, OutH := NumGet(&RECT, 12, "Int") - OutY 291 | return (ErrorLevel = "FAIL") ? false : true 292 | } 293 | ;======================================================================================= 294 | ; Method: GetButtonState 295 | ; Description: Retrieves the state of a button based on a querry. 296 | ; Parameters: 297 | ; StateQuerry: Enter one of the following words to get the state of the button: 298 | ; Checked, Enabled, Hidden, Highlighted, Indeterminate, Pressed. 299 | ; Return: The TRUE if the StateQuerry is true, FALSE if it's not. 300 | ;======================================================================================= 301 | GetButtonState(Button, StateQuerry) 302 | { 303 | this.GetButton(Button, BtnID) 304 | If (this[ "TB_ISBUTTON" StateQuerry] ) 305 | Msg := this[ "TB_ISBUTTON" StateQuerry ] 306 | SendMessage, Msg, BtnID, 0,, % "ahk_id " this.tbHwnd 307 | return ErrorLevel ? true : false 308 | } 309 | ;======================================================================================= 310 | ; Method: GetCount 311 | ; Description: Retrieves the total number of buttons. 312 | ; Return: The total number of buttons in the toolbar. 313 | ;======================================================================================= 314 | GetCount() 315 | { 316 | SendMessage, this.TB_BUTTONCOUNT, 0, 0,, % "ahk_id " this.tbHwnd 317 | return ErrorLevel 318 | } 319 | ;======================================================================================= 320 | ; Method: GetHiddenButtons 321 | ; Description: Retrieves which buttons are hidden when the toolbar size is 322 | ; smaller then the total size of the buttons it has. 323 | ; This method is most useful when the toolbar is a child window of 324 | ; a Rebar control, in order to show a menu when the chevron is 325 | ; pushed. It does not retrieve buttons hidden by gui size. 326 | ; Return: An array with all buttons hidden by the Rebar band. Each key 327 | ; in the array has 4 properties: ID, Text, Label and Icon. 328 | ;======================================================================================= 329 | GetHiddenButtons() 330 | { 331 | ControlGetPos,,, tbWidth,,, % "ahk_id " this.tbHwnd 332 | VarSetCapacity(RECT, 16, 0), HiddenButtons := [] 333 | Loop, % this.GetCount() 334 | { 335 | SendMessage, this.TB_GETITEMRECT, A_Index-1, &RECT,, % "ahk_id " this.tbHwnd 336 | If (NumGet(&RECT, 8, "Int") > tbWidth) 337 | this.GetButton(A_Index, ID, Text, "", "", Icon) 338 | , HiddenButtons.Push({ID: ID, Text: Text, Label: this.Labels[ID], Icon: Icon}) 339 | } 340 | return HiddenButtons 341 | } 342 | ;======================================================================================= 343 | ; Method: Insert 344 | ; Description: Insert button(s) in specified postion. 345 | ; To insert a separator call this method without parameters. 346 | ; Parameters: 347 | ; Position: 1-based index of button position to insert the new buttons. 348 | ; Options: Same as Add(). 349 | ; Buttons: Same as Add(). 350 | ; Return: TRUE if successful, FALSE if there was a problem. 351 | ;======================================================================================= 352 | Insert(Position, Options := "Enabled", Buttons*) 353 | { 354 | If (!Buttons.Length()) 355 | { 356 | this.BtnSep(TBBUTTON, Options) 357 | SendMessage, this.TB_INSERTBUTTON, Position-1, &TBBUTTON,, % "ahk_id " this.tbHwnd 358 | If (ErrorLevel = "FAIL") 359 | return false 360 | } 361 | Else If (Options = "") 362 | Options := "Enabled" 363 | For i, Button in Buttons 364 | { 365 | If !(this.SendMessage(Button, Options, this.TB_INSERTBUTTON, (Position-1)+(i-1))) 366 | return false 367 | } 368 | return true 369 | } 370 | ;======================================================================================= 371 | ; Method: LabelToIndex 372 | ; Description: Converts a button label to its index in a toolbar. 373 | ; Parameters: 374 | ; Label: Button's associated label or function. 375 | ; Return: The 1-based index for the button or FALSE if Label is invalid. 376 | ;======================================================================================= 377 | LabelToIndex(Label) 378 | { 379 | For ID, L in this.Labels 380 | { 381 | If (L = Label) 382 | { 383 | SendMessage, this.TB_COMMANDTOINDEX, ID, 0,, % "ahk_id " this.tbHwnd 384 | return ErrorLevel+1 385 | } 386 | } 387 | return false 388 | } 389 | ;======================================================================================= 390 | ; Method: ModifyButton 391 | ; Description: Sets button states. 392 | ; Parameters: 393 | ; Button: 1-based index of the button. 394 | ; State: Enter one word from the follwing list to change a button's 395 | ; state: Check, Enable, Hide, Mark, Press. 396 | ; Set: Enter TRUE or FALSE to set the state on/off. 397 | ; Return: TRUE if successful, FALSE if there was a problem. 398 | ;======================================================================================= 399 | ModifyButton(Button, State, Set := true) 400 | { 401 | If State not in CHECK,ENABLE,HIDE,MARK,PRESS 402 | return false 403 | Message := this[ "TB_" State "BUTTON"] 404 | , this.GetButton(Button, BtnID) 405 | SendMessage, Message, BtnID, Set,, % "ahk_id " this.tbHwnd 406 | return (ErrorLevel = "FAIL") ? false : true 407 | } 408 | ;======================================================================================= 409 | ; Method: ModifyButtonInfo 410 | ; Description: Sets button parameters such as Icon and CommandID. 411 | ; Parameters: 412 | ; Button: 1-based index of the button. 413 | ; Property: Enter one word from the following list to select the Property 414 | ; to be set: Command, Image, Size, State, Style, Text, Label. 415 | ; Value: The value to be set in the selected Property. 416 | ; If Property is State or Style you can enter named values as 417 | ; in the Add options. 418 | ; Return: TRUE if successful, FALSE if there was a problem. 419 | ;======================================================================================= 420 | ModifyButtonInfo(Button, Property, Value) 421 | { 422 | If (Property = "Label") 423 | { 424 | this.GetButton(Button, ID), this.Labels[ID] := Value 425 | return true 426 | } 427 | If (Property = "State") || (Property = "Style") 428 | { 429 | If Value is Integer 430 | Value := Value 431 | Else 432 | { 433 | Loop, Parse, Value, %A_Space%%A_Tab% 434 | { 435 | If (this[ "TBSTATE_" A_LoopField ]) 436 | tbState += this[ "TBSTATE_" A_LoopField ] 437 | Else If (this[ "BTNS_" A_LoopField ] ) 438 | tbStyle += this[ "BTNS_" A_LoopField ] 439 | } 440 | Value := tb%Property% 441 | } 442 | } 443 | If (Property = "Command") 444 | this.GetButton(Button, "", "", "", "", "", Label), this.Labels[Value] := Label 445 | this.DefineBtnInfoStruct(TBBUTTONINFO, Property, Value) 446 | , this.GetButton(Button, BtnID) 447 | SendMessage, this.TB_SETBUTTONINFO, BtnID, &TBBUTTONINFO,, % "ahk_id " this.tbHwnd 448 | return (ErrorLevel = "FAIL") ? false : true 449 | } 450 | ;======================================================================================= 451 | ; Method: MoveButton 452 | ; Description: Moves a toolbar button (change order). 453 | ; Parameters: 454 | ; Button: 1-based index of the button to be moved. 455 | ; Target: 1-based index of the new position. 456 | ; Return: TRUE if successful, FALSE if there was a problem. 457 | ;======================================================================================= 458 | MoveButton(Button, Target) 459 | { 460 | SendMessage, this.TB_MOVEBUTTON, Button-1, Target-1,, % "ahk_id " this.tbHwnd 461 | return (ErrorLevel = "FAIL") ? false : true 462 | } 463 | ;======================================================================================= 464 | ; Method: OnMessage 465 | ; Description: Run label associated with button's Command identifier. 466 | ; This method should be called from a function monitoring the 467 | ; WM_COMMAND message. Pass the wParam as the CommandID. 468 | ; Parameters: 469 | ; CommandID: Command ID associated with the button. This is send via 470 | ; WM_COMMAND message, you must pass the wParam from 471 | ; inside a function that monitors this message. 472 | ; FuncParams: In case the button is associated with a valid function, 473 | ; you may pass optional parameters for the function call. 474 | ; You can pass any number of parameters. 475 | ; Return: TRUE if target label or function exists, or FALSE otherwise. 476 | ;======================================================================================= 477 | OnMessage(CommandID, FuncParams*) 478 | { 479 | If (IsLabel(this.Labels[CommandID])) 480 | { 481 | GoSub, % this.Labels[CommandID] 482 | return true 483 | } 484 | Else If (IsFunc(this.Labels[CommandID])) 485 | { 486 | BtnFunc := this.Labels[CommandID] 487 | , %BtnFunc%(FuncParams*) 488 | return true 489 | } 490 | Else 491 | return false 492 | } 493 | ;======================================================================================= 494 | ; Method: OnNotify 495 | ; Description: Handles toolbar notifications. 496 | ; This method should be called from a function monitoring the 497 | ; WM_NOTIFY message. Pass the lParam as the Param. 498 | ; The returned value should be used as return value for 499 | ; the monitoring function as well. 500 | ; Parameters: 501 | ; Param: The lParam from WM_NOTIFY message. 502 | ; MenuXPos: OutputVar to store the horizontal position for a menu. 503 | ; MenuYPos: OutputVar to store the vertical position for a menu. 504 | ; BtnLabel: OutputVar to store the label or function name associated with the button. 505 | ; ID: OutputVar to store the button's Command ID. 506 | ; AllowCustom: Set to FALSE to prevent customization of toolbars. 507 | ; AllowReset: Set to FALSE to prevent Reset button from restoring original buttons. 508 | ; HideHelp: Set to FALSE to show the Help button in the customize dialog. 509 | ; Return: The required return value for the function monitoring 510 | ; the the WM_NOTIFY message. 511 | ;======================================================================================= 512 | OnNotify(ByRef Param, ByRef MenuXPos := "", ByRef MenuYPos := "", ByRef BtnLabel := "", ByRef ID := "" 513 | , AllowCustom := true, AllowReset := true, HideHelp := true) 514 | { 515 | nCode := NumGet(Param + (A_PtrSize * 2), 0, "Int"), tbHwnd := NumGet(Param + 0, 0, "UPtr") 516 | If (tbHwnd != this.tbHwnd) 517 | return "" 518 | If (nCode = this.TBN_DROPDOWN) 519 | { 520 | ID := NumGet(Param + (A_PtrSize * 3), 0, "Int"), BtnLabel := this.Labels[ID] 521 | , VarSetCapacity(RECT, 16, 0) 522 | SendMessage, this.TB_GETRECT, ID, &RECT,, % "ahk_id " this.tbHwnd 523 | ControlGetPos, TBX, TBY,,,, % "ahk_id " this.tbHwnd 524 | MenuXPos := TBX + NumGet(&RECT, 0, "Int"), MenuYPos := TBY + NumGet(&RECT, 12, "Int") 525 | return false 526 | } 527 | Else 528 | BtnLabel := "", ID := "" 529 | If (nCode = this.TBN_QUERYINSERT) 530 | return AllowCustom 531 | If (nCode = this.TBN_QUERYDELETE) 532 | return AllowCustom 533 | If (nCode = this.TBN_GETBUTTONINFO) 534 | { 535 | iItem := NumGet(Param + (A_PtrSize * 3), 0, "Int") 536 | If (iItem = this.DefaultBtnInfo.Length()) 537 | return false 538 | For each, Member in this.DefaultBtnInfo[iItem+1] 539 | %each% := Member 540 | If (Text != "") 541 | { 542 | VarSetCapacity(BTNSTR, (StrPut(Text) * (A_IsUnicode ? 2 : 1), 0)) 543 | , StrPut(Text, &BTNSTR, StrPut(Text) * 2) 544 | SendMessage, this.TB_ADDSTRING, 0, &BTNSTR,, % "ahk_id " this.tbHwnd 545 | Index := ErrorLevel, this.DefaultBtnInfo[iItem+1]["Index"] := Index 546 | , this.DefaultBtnInfo[iItem+1]["Text"] := Text 547 | } 548 | NumPut(Icon, Param + (A_PtrSize * 4), 0, "Int") ; iBitmap 549 | , NumPut(ID, Param + (A_PtrSize * 4), 4, "Int") ; idCommand 550 | , NumPut(State, Param + (A_PtrSize * 4), 8, "Char") ; tbState 551 | , NumPut(Style, Param + (A_PtrSize * 4), 9, "Char") ; tbStyle 552 | , NumPut(Index, Param + (A_PtrSize * 4), 8 + (A_PtrSize * 2), "Int") ; iString 553 | return true 554 | } 555 | If (nCode = this.TBN_TOOLBARCHANGE) 556 | { 557 | CurrentButtons := this.Export(true) 558 | , this.Presets.Load(CurrentButtons) 559 | , CurrentButtons := "" 560 | } 561 | If (nCode = this.TBN_RESET) 562 | { 563 | If (AllowReset) 564 | { 565 | this.Reset() 566 | return 2 567 | } 568 | } 569 | If (nCode = this.TBN_INITCUSTOMIZE) 570 | return HideHelp 571 | return "" 572 | } 573 | ;======================================================================================= 574 | ; Method: Reset 575 | ; Description: Restores all toolbar's buttons to default layout. 576 | ; Default layout is set by the buttons added. This can be changed 577 | ; calling the SetDefault method. 578 | ; Return: TRUE if successful, FALSE if there was a problem. 579 | ;======================================================================================= 580 | Reset() 581 | { 582 | BtnsArray := IsObject(CustomArray) ? CustomArray : this.DefaultBtnInfo 583 | , this.Get("", "", Rows) 584 | Loop, % this.GetCount() 585 | this.Delete(1) 586 | For each, Button in BtnsArray 587 | { 588 | For each, Member in Button 589 | %each% := Member 590 | If ((Rows > 1) && (Style = this.BTNS_SEP)) 591 | State := 0x24 592 | If (Text != "") 593 | { 594 | VarSetCapacity(BTNSTR, (StrPut(Text) * (A_IsUnicode ? 2 : 1), 0)) 595 | , StrPut(Text, &BTNSTR, StrPut(Text) * 2) 596 | SendMessage, this.TB_ADDSTRING, 0, &BTNSTR,, % "ahk_id " this.tbHwnd 597 | Index := ErrorLevel 598 | } 599 | VarSetCapacity(TBBUTTON, 8 + (A_PtrSize * 3), 0) 600 | , NumPut(Icon, TBBUTTON, 0, "Int") 601 | , NumPut(ID, TBBUTTON, 4, "Int") 602 | , NumPut(State, TBBUTTON, 8, "Char") 603 | , NumPut(Style, TBBUTTON, 9, "Char") 604 | , NumPut(Index, TBBUTTON, 8 + (A_PtrSize * 2), "Int") 605 | SendMessage, this.TB_ADDBUTTONS, 1, &TBBUTTON,, % "ahk_id " this.tbHwnd 606 | } 607 | return (ErrorLevel = "FAIL") ? false : true 608 | } 609 | ;======================================================================================= 610 | ; Method: SetButtonSize 611 | ; Description: Sets the size of buttons on a toolbar. Affects current buttons. 612 | ; Parameters: 613 | ; W: Width of buttons, in pixels 614 | ; H: Height of buttons, in pixels 615 | ; Return: TRUE if successful, FALSE if there was a problem. 616 | ;======================================================================================= 617 | SetButtonSize(W, H) 618 | { 619 | Long := this.MakeLong(W, H) 620 | SendMessage, this.TB_SETBUTTONSIZE, 0, Long,, % "ahk_id " this.tbHwnd 621 | return (ErrorLevel = "FAIL") ? false : true 622 | } 623 | ;======================================================================================= 624 | ; Method: SetDefault 625 | ; Description: Sets the internal default layout to be used when customizing or 626 | ; when the Reset method is called. 627 | ; Parameters: 628 | ; Options: Same as Add(). 629 | ; Buttons: Same as Add(). 630 | ; Return: Always TRUE. 631 | ;======================================================================================= 632 | SetDefault(Options := "Enabled", Buttons*) 633 | { 634 | this.DefaultBtnInfo := [] 635 | If (!Buttons.Length()) 636 | this.DefaultBtnInfo.Push({Icon: -1, ID: "", State: "" 637 | , Style: this.BTNS_SEP, Text: "", Label: ""}) 638 | If (Options = "") 639 | Options := "Enabled" 640 | For each, Button in Buttons 641 | this.SendMessage(Button, Options) 642 | return true 643 | } 644 | ;======================================================================================= 645 | ; Method: SetExStyle 646 | ; Description: Sets toolbar's extended style. 647 | ; Parameters: 648 | ; Style: Enter one or more words, separated by space or tab, from the 649 | ; following list to set toolbar's extended styles: 650 | ; Doublebuffer, DrawDDArrows, HideClippedButtons, 651 | ; MixedButtons. 652 | ; You may also enter an integer value to define the style. 653 | ; Return: TRUE if successful, FALSE if there was a problem. 654 | ;======================================================================================= 655 | SetExStyle(Style) 656 | { 657 | If Style is Integer 658 | tbStyle_Ex_ := Style 659 | Else 660 | { 661 | Loop, Parse, Style, %A_Space%%A_Tab% 662 | { 663 | If (this[ "TBSTYLE_EX_" A_LoopField ] ) 664 | tbStyle_Ex_ += this[ "TBSTYLE_EX_" A_LoopField ] 665 | } 666 | } 667 | SendMessage, this.TB_SETEXTENDEDSTYLE, 0, tbStyle_Ex_,, % "ahk_id " this.tbHwnd 668 | } 669 | ;======================================================================================= 670 | ; Method: SetHotItem 671 | ; Description: Sets the hot item on a toolbar. 672 | ; Parameters: 673 | ; Button: 1-based index of the button. 674 | ; Return: TRUE if successful, FALSE if there was a problem. 675 | ;======================================================================================= 676 | SetHotItem(Button) 677 | { 678 | SendMessage, this.TB_SETHOTITEM, Button-1, 0,, % "ahk_id " this.tbHwnd 679 | return (ErrorLevel = "FAIL") ? false : true 680 | } 681 | ;======================================================================================= 682 | ; Method: SetImageList 683 | ; Description: Sets an ImageList to the toolbar control. 684 | ; Parameters: 685 | ; IL_Default: ImageList ID of default ImageList. 686 | ; IL_Hot: ImageList ID of Hot ImageList. 687 | ; IL_Pressed: ImageList ID of Pressed ImageList. 688 | ; IL_Disabled: ImageList ID of Disabled ImageList. 689 | ; Return: TRUE if successful, FALSE if there was a problem. 690 | ;======================================================================================= 691 | SetImageList(IL_Default, IL_Hot := "", IL_Pressed := "", IL_Disabled := "") 692 | { 693 | SendMessage, this.TB_SETIMAGELIST, 0, IL_Default,, % "ahk_id " this.tbHwnd 694 | If (IL_Hot) 695 | SendMessage, this.TB_SETHOTIMAGELIST, 0, IL_Hot,, % "ahk_id " this.tbHwnd 696 | If (IL_Pressed) 697 | SendMessage, this.TB_SETPRESSEDIMAGELIST, 0, IL_Pressed,, % "ahk_id " this.tbHwnd 698 | If (IL_Disabled) 699 | SendMessage, this.TB_SETDISABLEDIMAGELIST, 0, IL_Disabled,, % "ahk_id " this.tbHwnd 700 | return (ErrorLevel = "FAIL") ? false : true 701 | } 702 | ;======================================================================================= 703 | ; Method: SetIndent 704 | ; Description: Sets the indentation for the first button on a toolbar. 705 | ; Parameters: 706 | ; Value: Value specifying the indentation, in pixels. 707 | ; Return: TRUE if successful, FALSE if there was a problem. 708 | ;======================================================================================= 709 | SetIndent(Value) 710 | { 711 | SendMessage, this.TB_SETINDENT, Value, 0,, % "ahk_id " this.tbHwnd 712 | return (ErrorLevel = "FAIL") ? false : true 713 | } 714 | ;======================================================================================= 715 | ; Method: SetListGap 716 | ; Description: Sets the distance between icons and text on a toolbar. 717 | ; Parameters: 718 | ; Value: The gap, in pixels, between buttons on the toolbar. 719 | ; Return: TRUE if successful, FALSE if there was a problem. 720 | ;======================================================================================= 721 | SetListGap(Value) 722 | { 723 | SendMessage, this.TB_SETLISTGAP, Value, 0,, % "ahk_id " this.tbHwnd 724 | return (ErrorLevel = "FAIL") ? false : true 725 | } 726 | ;======================================================================================= 727 | ; Method: SetMaxTextRows 728 | ; Description: Sets maximum number of text rows for button captions. 729 | ; Parameters: 730 | ; MaxRows: Maximum number of text rows. If omitted defaults to 0. 731 | ; Return: TRUE if successful, FALSE if there was a problem. 732 | ;======================================================================================= 733 | SetMaxTextRows(MaxRows := 0) 734 | { 735 | SendMessage, this.TB_SETMAXTEXTROWS, MaxRows, 0,, % "ahk_id " this.tbHwnd 736 | return (ErrorLevel = "FAIL") ? false : true 737 | } 738 | ;======================================================================================= 739 | ; Method: SetPadding 740 | ; Description: Sets the padding for icons a toolbar. 741 | ; Parameters: 742 | ; X: Horizontal padding, in pixels 743 | ; Y: Vertical padding, in pixels 744 | ; Return: TRUE if successful, FALSE if there was a problem. 745 | ;======================================================================================= 746 | SetPadding(X, Y) 747 | { 748 | Long := this.MakeLong(X, Y) 749 | SendMessage, this.TB_SETPADDING, 0, Long,, % "ahk_id " this.tbHwnd 750 | return (ErrorLevel = "FAIL") ? false : true 751 | } 752 | ;======================================================================================= 753 | ; Method: SetRows 754 | ; Description: Sets the number of rows for a toolbar. 755 | ; Parameters: 756 | ; Rows: Number of rows to set. If omitted defaults to 0. 757 | ; AddMore: Indicates whether to create more rows than requested when the 758 | ; system cannot create the number of rows specified. 759 | ; If TRUE, the system creates more rows. If FALSE, the system 760 | ; creates fewer rows. 761 | ; Return: TRUE if successful, FALSE if there was a problem. 762 | ;======================================================================================= 763 | SetRows(Rows := 0, AddMore := false) 764 | { 765 | Long := this.MakeLong(Rows, AddMore) 766 | SendMessage, this.TB_SETROWS, Long,,, % "ahk_id " this.tbHwnd 767 | return (ErrorLevel = "FAIL") ? false : true 768 | } 769 | ;======================================================================================= 770 | ; Method: ToggleStyle 771 | ; Description: Toggles toolbar's style. 772 | ; Parameters: 773 | ; Style: Enter zero or more words, separated by space or tab, from the 774 | ; following list to toggle toolbar's styles: 775 | ; AltDrag, CustomErase, Flat, List, RegisterDrop, Tooltips, 776 | ; Transparent, Wrapable, Adjustable, Border, ThickFrame, 777 | ; TabStop. 778 | ; You may also enter an integer value to define the style. 779 | ; Return: TRUE if a valid style is passed, or FALSE otherwise. 780 | ;======================================================================================= 781 | ToggleStyle(Style) 782 | { 783 | If Style is Integer 784 | tbStyle := Style 785 | Else 786 | { 787 | Loop, Parse, Style, %A_Space%%A_Tab% 788 | { 789 | If (this[ "TBSTYLE_" A_LoopField ] ) 790 | tbStyle += this[ "TBSTYLE_" A_LoopField ] 791 | } 792 | } 793 | ; TB_SETSTYLE moves the toolbar away from its position for some reason. 794 | ; SendMessage, this.TB_SETSTYLE, 0, tbStyle,, % "ahk_id " this.tbHwnd 795 | If (tbStyle != "") 796 | { 797 | WinSet, Style, ^%tbStyle%, % "ahk_id " this.tbHwnd 798 | return true 799 | } 800 | Else 801 | return false 802 | } 803 | ;======================================================================================= 804 | ; Presets Methods These methods are used exclusively by the Presets Object. 805 | ; Presets can be used to quickly change buttons of a toolbar 806 | ; to predetermined or saved layouts. 807 | ;======================================================================================= 808 | Class tbPresets extends Toolbar.Private 809 | { 810 | ;======================================================================================= 811 | ; Method: Presets.Delete 812 | ; Description: Deletes the layout of the specified slot. 813 | ; Parameters: 814 | ; Slot: Number of the slot containing the layout to be deleted. 815 | ; Return: TRUE if the slot contains a layout, or FALSE otherwise. 816 | ;======================================================================================= 817 | Delete(Slot) 818 | { 819 | If (IsObject(this[Slot])) 820 | { 821 | this.Delete(Slot) 822 | return true 823 | } 824 | Else 825 | return false 826 | } 827 | ;======================================================================================= 828 | ; Method: Presets.Export 829 | ; Description: Returns a text string with buttons and order in Add and 830 | ; Insert methods compatible format from the specified slot. 831 | ; Parameters: 832 | ; Slot: Number of the slot in which to save the layout. 833 | ; ArrayOut: Set to TRUE to return an object array. The returned object 834 | ; format is compatible with Presets.Save and Presets.Load 835 | ; methods, which can be used to save and load layout presets. 836 | ; Return: A text string with buttons information to be exported. 837 | ;======================================================================================= 838 | Export(Slot, ArrayOut := false) 839 | { 840 | BtnArray := [] 841 | For i, Button in this[Slot] 842 | { 843 | For each, Member in Button 844 | %each% := Member 845 | BtnString .= (Label ? (Label (Text ? "=" Text : "") 846 | . ":" Icon+1 (Style ? "(" Style ")" : "")) : "") ", " 847 | If (ArrayOut) 848 | BtnArray.Push({Icon: Icon, ID: ID, State: State 849 | , Style: Style, Text: Text, Label: Label}) 850 | } 851 | return ArrayOut ? BtnArray : RTrim(BtnString, ", ") 852 | } 853 | ;======================================================================================= 854 | ; Method: Presets.Import 855 | ; Description: Imports a buttons layout from a string in Add/Insert methods 856 | ; format and saves it into the specified slot. 857 | ; Parameters: 858 | ; Slot: Number of the slot in which to save the layout. 859 | ; Options: Same as Add(). 860 | ; Buttons: Same as Add(). 861 | ; Return: Always TRUE. 862 | ;======================================================================================= 863 | Import(Slot, Options := "Enabled", Buttons*) 864 | { 865 | BtnArray := [] 866 | If (Options = "") 867 | Options := "Enabled" 868 | For each, Button in Buttons 869 | { 870 | If (RegExMatch(Button, "^(\W?)(\w+)[=\s]?(.*)?:(\d+)\(?(.*?)?\)?$", Key)) 871 | { 872 | If (Key1) 873 | continue 874 | idCommand := this.GenerateRandomID() 875 | , iString := Key3, iBitmap := Key4 876 | , Struct := this.DefineBtnStruct(TBBUTTON, iBitmap, idCommand, iString, Key5 ? Key5 : Options) 877 | , Struct.Label := Key2, BtnArray.Push(Struct) 878 | } 879 | Else 880 | Struct := this.BtnSep(TBBUTTON, Options), BtnArray.Push(Struct) 881 | } 882 | this[Slot] := BtnArray 883 | return true 884 | } 885 | ;======================================================================================= 886 | ; Method: Presets.Load 887 | ; Description: Loads a layout from the specified slot. 888 | ; Parameters: 889 | ; Slot: Number of the slot containing the layout to be loaded. 890 | ; For convenience and internal operations this parameter can be an 891 | ; object in the same format of Presets.Save Buttons parameter. 892 | ; Return: TRUE if the slot contains a layout, or FALSE otherwise. 893 | ;======================================================================================= 894 | Load(Slot) 895 | { 896 | If (IsObject(Slot)) 897 | Buttons := Slot 898 | Else 899 | Buttons := this[Slot] 900 | If (!IsObject(Buttons)) 901 | return false 902 | SendMessage, this.TB_GETROWS, 0, 0,, % "ahk_id " this.tbHwnd 903 | Rows := ErrorLevel 904 | SendMessage, this.TB_BUTTONCOUNT, 0, 0,, % "ahk_id " this.tbHwnd 905 | Loop, % ErrorLevel 906 | SendMessage, this.TB_DELETEBUTTON, 0, 0,, % "ahk_id " this.tbHwnd 907 | For each, Button in Buttons 908 | { 909 | For each, Member in Button 910 | %each% := Member 911 | If ((Rows > 1) && (Style = this.BTNS_SEP)) 912 | State := 0x24 913 | If (Text != "") 914 | { 915 | VarSetCapacity(BTNSTR, (StrPut(Text) * (A_IsUnicode ? 2 : 1), 0)) 916 | , StrPut(Text, &BTNSTR, StrPut(Text) * 2) 917 | SendMessage, this.TB_ADDSTRING, 0, &BTNSTR,, % "ahk_id " this.tbHwnd 918 | Index := ErrorLevel 919 | } 920 | VarSetCapacity(TBBUTTON, 8 + (A_PtrSize * 3), 0) 921 | , NumPut(Icon, TBBUTTON, 0, "Int") 922 | , NumPut(ID, TBBUTTON, 4, "Int") 923 | , NumPut(State, TBBUTTON, 8, "Char") 924 | , NumPut(Style, TBBUTTON, 9, "Char") 925 | , NumPut(Index, TBBUTTON, 8 + (A_PtrSize * 2), "Int") 926 | SendMessage, this.TB_ADDBUTTONS, 1, &TBBUTTON,, % "ahk_id " this.tbHwnd 927 | } 928 | return (ErrorLevel = "FAIL") ? false : true 929 | } 930 | ;======================================================================================= 931 | ; Method: Presets.Save 932 | ; Description: Saves a buttons layout as a preset into the specified slot. 933 | ; Parameters: 934 | ; Slot: Number of the slot in which to save the layout. There is no 935 | ; predefined limit of slots. 936 | ; Buttons: Buttons array must be in a valid format. You can use the Export 937 | ; Toolbar Method (not the Preset Method of the same name) 938 | ; passing TRUE to the ArrayOut parameter to return a valid 939 | ; array to be used with this method. 940 | ; Return: TRUE if Buttons is an object, or FALSE otherwise. 941 | ;======================================================================================= 942 | Save(Slot, Buttons) 943 | { 944 | If (IsObject(Buttons)) 945 | { 946 | this[Slot] := Buttons 947 | return true 948 | } 949 | Else 950 | return false 951 | } 952 | } 953 | ;======================================================================================= 954 | ; Private Class This class is used internally. 955 | ;======================================================================================= 956 | Class Private 957 | { 958 | ;======================================================================================= 959 | ; Private Properties 960 | ;======================================================================================= 961 | ; Messages 962 | Static TB_ADDBUTTONS := 0x0414 963 | Static TB_ADDSTRING := A_IsUnicode ? 0x044D : 0x041C 964 | Static TB_AUTOSIZE := 0x0421 965 | Static TB_BUTTONCOUNT := 0x0418 966 | Static TB_CHECKBUTTON := 0x0402 967 | Static TB_COMMANDTOINDEX := 0x0419 968 | Static TB_CUSTOMIZE := 0x041B 969 | Static TB_DELETEBUTTON := 0x0416 970 | Static TB_ENABLEBUTTON := 0x0401 971 | Static TB_GETBUTTON := 0x0417 972 | Static TB_GETBUTTONSIZE := 0x043A 973 | Static TB_GETBUTTONTEXT := A_IsUnicode ? 0x044B : 0x042D 974 | Static TB_GETEXTENDEDSTYLE := 0x0455 975 | Static TB_GETHOTITEM := 0x0447 976 | Static TB_GETIMAGELIST := 0x0431 977 | Static TB_GETIMAGELISTCOUNT := 0x0462 978 | Static TB_GETITEMDROPDOWNRECT := 0x0467 979 | Static TB_GETITEMRECT := 0x041D 980 | Static TB_GETMAXSIZE := 0x0453 981 | Static TB_GETPADDING := 0x0456 982 | Static TB_GETRECT := 0x0433 983 | Static TB_GETROWS := 0x0428 984 | Static TB_GETSTATE := 0x0412 985 | Static TB_GETSTYLE := 0x0439 986 | Static TB_GETSTRING := A_IsUnicode ? :0x045B 0x045C 987 | Static TB_GETTEXTROWS := 0x043D 988 | Static TB_HIDEBUTTON := 0x0404 989 | Static TB_INDETERMINATE := 0x0405 990 | Static TB_INSERTBUTTON := A_IsUnicode ? 0x0443 : 0x0415 991 | Static TB_ISBUTTONCHECKED := 0x040A 992 | Static TB_ISBUTTONENABLED := 0x0409 993 | Static TB_ISBUTTONHIDDEN := 0x040C 994 | Static TB_ISBUTTONHIGHLIGHTED := 0x040E 995 | Static TB_ISBUTTONINDETERMINATE := 0x040D 996 | Static TB_ISBUTTONPRESSED := 0x040B 997 | Static TB_MARKBUTTON := 0x0406 998 | Static TB_MOVEBUTTON := 0x0452 999 | Static TB_PRESSBUTTON := 0x0403 1000 | Static TB_SETBUTTONINFO := A_IsUnicode ? 0x0440 : 0x0442 1001 | Static TB_SETBUTTONSIZE := 0x041F 1002 | Static TB_SETBUTTONWIDTH := 0x043B 1003 | Static TB_SETDISABLEDIMAGELIST := 0x0436 1004 | Static TB_SETEXTENDEDSTYLE := 0x0454 1005 | Static TB_SETHOTIMAGELIST := 0x0434 1006 | Static TB_SETHOTITEM := 0x0448 1007 | Static TB_SETHOTITEM2 := 0x045E 1008 | Static TB_SETIMAGELIST := 0x0430 1009 | Static TB_SETINDENT := 0x042F 1010 | Static TB_SETLISTGAP := 0x0460 1011 | Static TB_SETMAXTEXTROWS := 0x043C 1012 | Static TB_SETPADDING := 0x0457 1013 | Static TB_SETPRESSEDIMAGELIST := 0x0468 1014 | Static TB_SETROWS := 0x0427 1015 | Static TB_SETSTATE := 0x0411 1016 | Static TB_SETSTYLE := 0x0438 1017 | ; Styles 1018 | Static TBSTYLE_ALTDRAG := 0x0400 1019 | Static TBSTYLE_CUSTOMERASE := 0x2000 1020 | Static TBSTYLE_FLAT := 0x0800 1021 | Static TBSTYLE_LIST := 0x1000 1022 | Static TBSTYLE_REGISTERDROP := 0x4000 1023 | Static TBSTYLE_TOOLTIPS := 0x0100 1024 | Static TBSTYLE_TRANSPARENT := 0x8000 1025 | Static TBSTYLE_WRAPABLE := 0x0200 1026 | Static TBSTYLE_ADJUSTABLE := 0x20 1027 | Static TBSTYLE_BORDER := 0x800000 1028 | Static TBSTYLE_THICKFRAME := 0x40000 1029 | Static TBSTYLE_TABSTOP := 0x10000 1030 | ; ExStyles 1031 | Static TBSTYLE_EX_DOUBLEBUFFER := 0x80 ; // Double Buffer the toolbar 1032 | Static TBSTYLE_EX_DRAWDDARROWS := 0x01 1033 | Static TBSTYLE_EX_HIDECLIPPEDBUTTONS := 0x10 ; // don't show partially obscured buttons 1034 | Static TBSTYLE_EX_MIXEDBUTTONS := 0x08 1035 | Static TBSTYLE_EX_MULTICOLUMN := 0x02 ; // Intended for internal use; not recommended for use in applications. 1036 | Static TBSTYLE_EX_VERTICAL := 0x04 ; // Intended for internal use; not recommended for use in applications. 1037 | ; Button states 1038 | Static TBSTATE_CHECKED := 0x01 1039 | Static TBSTATE_ELLIPSES := 0x40 1040 | Static TBSTATE_ENABLED := 0x04 1041 | Static TBSTATE_HIDDEN := 0x08 1042 | Static TBSTATE_INDETERMINATE := 0x10 1043 | Static TBSTATE_MARKED := 0x80 1044 | Static TBSTATE_PRESSED := 0x02 1045 | Static TBSTATE_WRAP := 0x20 1046 | ; Button styles 1047 | Static BTNS_BUTTON := 0x00 ; TBSTYLE_BUTTON 1048 | Static BTNS_SEP := 0x01 ; TBSTYLE_SEP 1049 | Static BTNS_CHECK := 0x02 ; TBSTYLE_CHECK 1050 | Static BTNS_GROUP := 0x04 ; TBSTYLE_GROUP 1051 | Static BTNS_CHECKGROUP := 0x06 ; TBSTYLE_CHECKGROUP // (TBSTYLE_GROUP | TBSTYLE_CHECK) 1052 | Static BTNS_DROPDOWN := 0x08 ; TBSTYLE_DROPDOWN 1053 | Static BTNS_AUTOSIZE := 0x10 ; TBSTYLE_AUTOSIZE // automatically calculate the cx of the button 1054 | Static BTNS_NOPREFIX := 0x20 ; TBSTYLE_NOPREFIX // this button should not have accel prefix 1055 | Static BTNS_SHOWTEXT := 0x40 ; // ignored unless TBSTYLE_EX_MIXEDBUTTONS is set 1056 | Static BTNS_WHOLEDROPDOWN := 0x80 ; // draw drop-down arrow, but without split arrow section 1057 | ; TB_GETBITMAPFLAGS 1058 | Static TBBF_LARGE := 0x00000001 1059 | Static TBIF_BYINDEX := 0x80000000 ; // this specifies that the wparam in Get/SetButtonInfo is an index, not id 1060 | Static TBIF_COMMAND := 0x00000020 1061 | Static TBIF_IMAGE := 0x00000001 1062 | Static TBIF_LPARAM := 0x00000010 1063 | Static TBIF_SIZE := 0x00000040 1064 | Static TBIF_STATE := 0x00000004 1065 | Static TBIF_STYLE := 0x00000008 1066 | Static TBIF_TEXT := 0x00000002 1067 | ; Notifications 1068 | Static TBN_BEGINADJUST := -703 1069 | Static TBN_BEGINDRAG := -701 1070 | Static TBN_CUSTHELP := -709 1071 | Static TBN_DELETINGBUTTON := -715 1072 | Static TBN_DRAGOUT := -714 1073 | Static TBN_DRAGOVER := -727 1074 | Static TBN_DROPDOWN := -710 1075 | Static TBN_DUPACCELERATOR := -725 1076 | Static TBN_ENDADJUST := -704 1077 | Static TBN_ENDDRAG := -702 1078 | Static TBN_GETBUTTONINFO := -720 ; A_IsUnicode ? -720 : -700 1079 | Static TBN_GETDISPINFO := A_IsUnicode ? -717 : -716 1080 | Static TBN_GETINFOTIP := A_IsUnicode ? -719 : -718 1081 | Static TBN_GETOBJECT := -712 1082 | Static TBN_HOTITEMCHANGE := -713 1083 | Static TBN_INITCUSTOMIZE := -723 1084 | Static TBN_MAPACCELERATOR := -728 1085 | Static TBN_QUERYDELETE := -707 1086 | Static TBN_QUERYINSERT := -706 1087 | Static TBN_RESET := -705 1088 | Static TBN_RESTORE := -721 1089 | Static TBN_SAVE := -722 1090 | Static TBN_TOOLBARCHANGE := -708 1091 | Static TBN_WRAPACCELERATOR := -726 1092 | Static TBN_WRAPHOTITEM := -724 1093 | ;======================================================================================= 1094 | ; Meta-Functions 1095 | ; 1096 | ; Properties: 1097 | ; tbHwnd: Toolbar's Hwnd. 1098 | ; DefaultBtnInfo: Stores information about button's original structures. 1099 | ; Presets: This is a special object used to save and load buttons 1100 | ; layouts. It has its own methods. 1101 | ;======================================================================================= 1102 | __New(hToolbar) 1103 | { 1104 | this.tbHwnd := hToolbar 1105 | , this.DefaultBtnInfo := [] 1106 | , this.Presets := {tbHwnd: hToolbar, Base: Toolbar.tbPresets} 1107 | } 1108 | ;======================================================================================= 1109 | __Delete() 1110 | { 1111 | this.RemoveAt(1, this.Length()) 1112 | , this.SetCapacity(0) 1113 | , this.base := "" 1114 | } 1115 | ;======================================================================================= 1116 | ; Private Methods 1117 | ;======================================================================================= 1118 | ; Method: SendMessage 1119 | ; Description: Sends a message to create or modify a button. 1120 | ;======================================================================================= 1121 | SendMessage(Button, Options, Message := "", Param := "") 1122 | { 1123 | If (RegExMatch(Button, "^(\W?)(\w+)[=\s]?(.*)?:(\d+)\(?(.*?)?\)?$", Key)) 1124 | { 1125 | idCommand := this.GenerateRandomID() 1126 | , iString := Key3, iBitmap := Key4 1127 | , this.Labels[idCommand] := Key2 1128 | , Struct := this.DefineBtnStruct(TBBUTTON, iBitmap, idCommand, iString, Key5 ? Key5 : Options) 1129 | , this.DefaultBtnInfo.Push(Struct) 1130 | If !(Key1) && (Message) 1131 | { 1132 | SendMessage, Message, Param, &TBBUTTON,, % "ahk_id " this.tbHwnd 1133 | If (ErrorLevel = "FAIL") 1134 | return false 1135 | } 1136 | } 1137 | Else 1138 | { 1139 | Struct := this.BtnSep(TBBUTTON, Options), this.DefaultBtnInfo.Push(Struct) 1140 | If (Message) 1141 | { 1142 | SendMessage, Message, Param, &TBBUTTON,, % "ahk_id " this.tbHwnd 1143 | If (ErrorLevel = "FAIL") 1144 | return false 1145 | } 1146 | } 1147 | return true 1148 | } 1149 | ;======================================================================================= 1150 | ; Method: DefineBtnStruct 1151 | ; Description: Creates a TBBUTTON structure. 1152 | ; Return: An array with the button structure values. 1153 | ;======================================================================================= 1154 | DefineBtnStruct(ByRef BtnVar, iBitmap := 0, idCommand := 0, iString := "", Options := "") 1155 | { 1156 | If Options is Integer 1157 | tbStyle := Options, tbState := this.TBSTATE_ENABLED 1158 | Else 1159 | { 1160 | Loop, Parse, Options, %A_Space%%A_Tab% 1161 | { 1162 | If (this[ "TBSTATE_" A_LoopField ]) 1163 | tbState += this[ "TBSTATE_" A_LoopField ] 1164 | Else If (this[ "BTNS_" A_LoopField ] ) 1165 | tbStyle += this[ "BTNS_" A_LoopField ] 1166 | Else If (RegExMatch(A_LoopField, "i)W(\d+)-(\d+)", MW)) 1167 | { 1168 | Long := this.MakeLong(MW1, MW2) 1169 | SendMessage, this.TB_SETBUTTONWIDTH, 0, Long,, % "ahk_id " this.tbHwnd 1170 | } 1171 | } 1172 | } 1173 | If (iString != "") 1174 | { 1175 | VarSetCapacity(BTNSTR, (StrPut(iString) * (A_IsUnicode ? 2 : 1), 0)) 1176 | , StrPut(iString, &BTNSTR, StrPut(iString) * 2) 1177 | SendMessage, this.TB_ADDSTRING, 0, &BTNSTR,, % "ahk_id " this.tbHwnd 1178 | StrIdx := ErrorLevel 1179 | } 1180 | Else 1181 | StrIdx := -1 1182 | VarSetCapacity(BtnVar, 8 + (A_PtrSize * 3), 0) 1183 | , NumPut(iBitmap-1, BtnVar, 0, "Int") 1184 | , NumPut(idCommand, BtnVar, 4, "Int") 1185 | , NumPut(tbState, BtnVar, 8, "Char") 1186 | , NumPut(tbStyle, BtnVar, 9, "Char") 1187 | , NumPut(StrIdx, BtnVar, 8 + (A_PtrSize * 2), "Ptr") 1188 | return {Icon: iBitmap-1, ID: idCommand, State: tbState 1189 | , Style: tbStyle, Text: iString, Label: this.Labels[idCommand]} 1190 | } 1191 | ;======================================================================================= 1192 | ; Method: DefineBtnInfoStruct 1193 | ; Description: Creates a TBBUTTONINFO structure for a specific member. 1194 | ;======================================================================================= 1195 | DefineBtnInfoStruct(ByRef BtnVar, Member, ByRef Value) 1196 | { 1197 | Static cbSize := 16 + (A_PtrSize * 4) 1198 | 1199 | VarSetCapacity(BtnVar, cbSize, 0) 1200 | , NumPut(cbSize, BtnVar, 0, "UInt") 1201 | If (this[ "TBIF_" Member] ) 1202 | dwMask := this[ "TBIF_" Member ] 1203 | , NumPut(dwMask, BtnVar, 4, "UInt") 1204 | If (dwMask = this.TBIF_COMMAND) 1205 | NumPut(Value, BtnVar, 8, "Int") ; idCommand 1206 | Else If (dwMask = this.TBIF_IMAGE) 1207 | Value := Value-1 1208 | , NumPut(Value, BtnVar, 12, "Int") ; iImage 1209 | Else If (dwMask = this.TBIF_STATE) 1210 | Value := (this[ "TBSTATE_" Value ]) ? this[ "TBSTATE_" Value ] : Value 1211 | , NumPut(Value, BtnVar, 16, "Char") ; fsState 1212 | Else If (dwMask = this.TBIF_STYLE) 1213 | Value := (this[ "BTNS_" Value ]) ? this[ "BTNS_" Value ] : Value 1214 | , NumPut(Value, BtnVar, 17, "Char") ; fsStyle 1215 | Else If (dwMask = this.TBIF_SIZE) 1216 | NumPut(Value, BtnVar, 18, "Short") ; cx 1217 | Else If (dwMask = this.TBIF_TEXT) 1218 | NumPut(&Value, BtnVar, 16 + (A_PtrSize * 2), "UPtr") ; pszText 1219 | } 1220 | ;======================================================================================= 1221 | ; Method: BtnSep 1222 | ; Description: Creates a TBBUTTON structure for a separator. 1223 | ; Return: An array with the button structure values. 1224 | ;======================================================================================= 1225 | BtnSep(ByRef BtnVar, Options := "") 1226 | { 1227 | tbStyle := this.BTNS_SEP 1228 | Loop, Parse, Options, %A_Space%%A_Tab% 1229 | { 1230 | If (this[ "TBSTATE_" A_LoopField ]) 1231 | tbState += this[ "TBSTATE_" A_LoopField ] 1232 | } 1233 | VarSetCapacity(BtnVar, 8 + (A_PtrSize * 3), 0) 1234 | , NumPut(tbState, BtnVar, 8, "Char") 1235 | , NumPut(tbStyle, BtnVar, 9, "Char") 1236 | return {Icon: -1, ID: "", State: tbState, Style: tbStyle, Text: "", Label: ""} 1237 | } 1238 | ;======================================================================================= 1239 | ; Method: GenerateRandomID 1240 | ; Description: Returns a random number to be used as Command ID. 1241 | ;======================================================================================= 1242 | GenerateRandomID() 1243 | { 1244 | While, (!Number || this.Labels.HasKey(Number)) 1245 | Random, Number, 1, 9999 1246 | return Number 1247 | } 1248 | ;======================================================================================= 1249 | ; Method: MakeLong 1250 | ; Description: Creates a LongWord from a LoWord and a HiWord. 1251 | ;======================================================================================= 1252 | MakeLong(LoWord, HiWord) 1253 | { 1254 | return (HiWord << 16) | (LoWord & 0xffff) 1255 | } 1256 | ;======================================================================================= 1257 | ; Method: MakeLong 1258 | ; Description: Extracts LoWord and HiWord from a LongWord. 1259 | ;======================================================================================= 1260 | MakeShort(Long, ByRef LoWord, ByRef HiWord) 1261 | { 1262 | LoWord := Long & 0xffff 1263 | , HiWord := Long >> 16 1264 | } 1265 | } 1266 | } --------------------------------------------------------------------------------