[Class] Toolbar - Create and modify (Updated 03/17/2016)

Post your working scripts, libraries and tools
User avatar
Pulover
Posts: 365
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

[Class] Toolbar - Create and modify (Updated 03/17/2016)

04 Oct 2013, 07:25

This class attempts to provide intuitive methods to work with toolbars created using Gui Custom controls.

Since the new Custom controls were implemented I've been waiting for someone to come up with a library or class to work with toolbars but as nothing has shown I decided to try and make one myself.

Screenshot:
Image

I've been learning from examples in MSDN and from Toolbar.ahk, included in majkinetor's impressive Forms Framework, to implement the most essential methods needed.

Features:
  • Add, insert, delete and modify buttons.
  • Add or insert various buttons in a single call with general and individual options.
  • Add default, hot, pressed and disabled Image Lists.
  • Export layouts.
  • Save, load, import and export presets.
  • Retrieve and change information about buttons and toolbars.
  • Supports customization and save/reset operations.
  • Supports vertical toolbars.

:arrow: Sources, documentation and examples on GitHub
 
Reference: Toolbar (MSDN)

See also Rebar
Last edited by Pulover on 17 Mar 2016, 06:19, edited 6 times in total.
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
User avatar
joedf
Posts: 5328
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: [Class] Toolbar - Create and modify

07 Nov 2013, 23:19

neat! :)
User avatar
Pulover
Posts: 365
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: [Class] Toolbar - Create and modify

08 Nov 2013, 04:13

joedf wrote:neat! :)

Thanks, joedf! Btw I've reverted the last update. Turned out I had misunderstand the request and the result was not very good... :P
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
User avatar
BGM
Posts: 331
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: [Class] Toolbar - Create and modify

20 Nov 2013, 21:08

Hi, Pulover. Does this new toolbar have a configurator? Majkenator's toolbar.ahk from the forms framework had a configuration window that would allow you to add and remove buttons.
Last edited by BGM on 21 Nov 2013, 22:28, edited 1 time in total.
User avatar
Pulover
Posts: 365
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: [Class] Toolbar - Create and modify

20 Nov 2013, 21:18

Hi BGM,

It does. Check out the Customize() method and the demo script to know how to implement it.
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
User avatar
BGM
Posts: 331
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: [Class] Toolbar - Create and modify

20 Nov 2013, 22:14

Thanks, Pulover - I played with it and it works fine. Figured out how to add a Customize button to the demo in less than 10 minutes!
The demo is wonderful, by the way.

Maybe you should add the Customize button to the demo, too?
User avatar
Pulover
Posts: 365
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: [Class] Toolbar - Create and modify

21 Nov 2013, 06:42

I didn't use the Customize method in the demo because I used CCS_ADJUSTABLE to show it when you double-click on an empty area of the toolbar. But I might add a button for the method too. Thanks.
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
User avatar
BGM
Posts: 331
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: [Class] Toolbar - Create and modify

21 Nov 2013, 21:21

Pulover, I am trying to adjust my script to use your class instead of the older forms framework toolbar.ahk.
The gosubs I am using detect whether the user held the shift key when they were called.
However, it seems that when I use this with the class_toolbar, the modifier keys get lost.

Here is what I have (the forum is escaping all my parentheses within the code-block, by the way....):
Spoiler

What do you recommend?
Last edited by BGM on 21 Nov 2013, 22:45, edited 5 times in total.
User avatar
BGM
Posts: 331
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: [Class] Toolbar - Create and modify

21 Nov 2013, 21:25

Also, Pulover, in my own script, when I call hMYtoolbar.Customize(), the customize window appears for a second and then goes away. I can see the buttons just fine on my toolbar, and they work well enough (except for what I mentioned in my other post), but the customizer is wrong. I confirm that 0x0020 is present in the toolbars options. What can I do?
User avatar
BGM
Posts: 331
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: [Class] Toolbar - Create and modify

21 Nov 2013, 22:25

Pulover, sorry to be so noisy, but I've another problem. And this one is a bit strange.
Spoiler

So it looks like the tooltip mechanism doesn't like similar numbers. It confuses 201 with 101 even though they are two different labels in the script.

I think this is a bug somewhere.
User avatar
Chef
Posts: 50
Joined: 14 Nov 2013, 13:01

Re: [Class] Toolbar - Create and modify

22 Nov 2013, 03:05

Hello Pulover,
I don't think autoResize resizes the width to fit buttons.
Is it meant to do that?
User avatar
Pulover
Posts: 365
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: [Class] Toolbar - Create and modify

22 Nov 2013, 07:51

BGM wrote:Pulover, I am trying to adjust my script to use your class instead of the older forms framework toolbar.ahk.
The gosubs I am using detect whether the user held the shift key when they were called.
However, it seems that when I use this with the class_toolbar, the modifier keys get lost.

What do you recommend?

Well, you didn't give me an example to try so I don't know how you're doing this check. I've tested here with a sample script and I could detect the shift key pressed on the target label.

Spoiler



BGM wrote:Also, Pulover, in my own script, when I call hMYtoolbar.Customize(), the customize window appears for a second and then goes away. I can see the buttons just fine on my toolbar, and they work well enough (except for what I mentioned in my other post), but the customizer is wrong. I confirm that 0x0020 is present in the toolbars options. What can I do?

I forgot to add a note that this method requires OnNotifiy() implemented to work. The demo above shows a simple way to use it.

BGM wrote:Pulover, sorry to be so noisy, but I've another problem. And this one is a bit strange.
Spoiler

So it looks like the tooltip mechanism doesn't like similar numbers. It confuses 201 with 101 even though they are two different labels in the script.

I think this is a bug somewhere.

In order to trigger an action the toolbar buttons are assigned to a CommandID, which is sent in a WM_COMMAND message. I didn't want to have to care about assigning those codes manually so I've created a function (StringToNumber()) that converts the label into a (possibly) unique code number. I don't recommend using labels that contain only numbers, not for toolbars nor for any project you're working on. Make them at least begin with a letter like L101. Or you can modify the function on the class to fit your needs.
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
User avatar
Pulover
Posts: 365
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: [Class] Toolbar - Create and modify

22 Nov 2013, 07:55

Chef wrote:Hello Pulover,
I don't think autoResize resizes the width to fit buttons.
Is it meant to do that?

Maybe you need CCS_NORESIZE (0x0004) and CCS_NOPARENTALIGN (0x0008) styles on your toolbar. Without them the toolbar is positioned and sized automatically to the gui.
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
User avatar
BGM
Posts: 331
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: [Class] Toolbar - Create and modify

22 Nov 2013, 09:39

Say, that simple_toolbar.ahk example is valuable! It provides an easy template to go by and quickly get results using your class script. I recommend posting it at the head of the thread along with the demo!

Pulover, adding the OnNotify fixed the customization window (thank you!).

Pulover, I understand what you mean about not using numbers as labels - but I've build my whole project to work by dynamically cycling through the numbers and then building variables from them. I'm not sure I want to re-figure out my code to undo that...

So I changed the StringToNumber() function to just return the parameter without doing anything to it.

And I also changed the Export function to use "|" as a separator instead of ", ". I'm not sure if that made any difference, but my button text issue seems to have cleared up!

Thanks again for your hlep!
Last edited by BGM on 22 Nov 2013, 11:46, edited 3 times in total.
User avatar
BGM
Posts: 331
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: [Class] Toolbar - Create and modify

22 Nov 2013, 09:50

Here is the function I am using to detect keys:
Spoiler


What is happening is that it will detect for "no modifier" and "control" but not for "shift" - when I say it won't detect, I mean that the messagebox doesn't even fire when I push shift. But it works fine for control. Strange, no? But if I try the same function whilst called from a hotkey instead of from the toolbar, it works perfectly. So something with the toolbar is causing shift not to be detected. I suppose it's the same thing that mixes up the button text. (I know this is hard to troubleshoot!)

**edit**
Ah, I've noticed something. If I shift+click the button, it makes certain separators in the toolbar appear and disappear - after that, the shift-function fires fine. So I think what is happening is that shift+click causes the toolbar to enter an editing mode.

Okay, after I removed CCS_ADJUSTABLE then this problem went away!
User avatar
Chef
Posts: 50
Joined: 14 Nov 2013, 13:01

Re: [Class] Toolbar - Create and modify

22 Nov 2013, 10:54

Those options have no effect when it comes to autoSizing width. You can see that yourself by adding +border option in your example.
But since I have TB library I just call TB_AUTOSIZE() which works like a charm.

Here its if your interested...

Code: [Select all] [Expand] [Download] (Script.ahk)GeSHi © Codebox Plus

User avatar
Pulover
Posts: 365
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: [Class] Toolbar - Create and modify

22 Nov 2013, 11:54

BGM wrote:Okay, after I removed CCS_ADJUSTABLE then this problem went away!

Good catch! I'll see what I can do about the tooltips when I have more time.
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
User avatar
Pulover
Posts: 365
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: [Class] Toolbar - Create and modify

22 Nov 2013, 12:02

Chef wrote:Those options have no effect when it comes to autoSizing width. You can see that yourself by adding +border option in your example.
But since I have TB library I just call TB_AUTOSIZE() which works like a charm.

I haven't tested yet but maybe there's a bug in the method. This wouldn't be the only bug in Microsoft common controls... I've used more than one workaround by majkinetor.

If you're using the toolbar with a resizable gui you might be interested in using a Rebar.

viewtopic.php?f=6&t=139
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
User avatar
BGM
Posts: 331
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: [Class] Toolbar - Create and modify

22 Nov 2013, 14:31

In my project, I have around 50 buttons.

I have a couple of ideas.

Upon program launch, the script (in my opinoin) should work like this:

Add all the possible buttons - of course, the coder has to add the routine to do that. That way, if there is an update of the script, the new buttons are available.

Layouts would consist only of visible buttons. The script would load a layout, and when a button is added, the script should check to see if the button exists before adding it - if it exists, the button's properties get updated (visibility, perhaps - whatever is set in the add() function's options).

THEN, since all the buttons are added at the start, there is no reason to save hidden buttons in the export. It seems to be less processing to just save visible buttons in the layout.

What do you think, Pulover?
User avatar
BGM
Posts: 331
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: [Class] Toolbar - Create and modify

22 Nov 2013, 14:37

Also, what is the difference between using myToolbar.export() and a layout? It seems that a layout is the same thing. If I export the current button set to a different key in the ini file, isn't that the same thing as saving a layout? That's what I understand from the demo, anyway.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: lordsephirote, Randy31416 and 15 guests