Now that more people are moving off Windows XP we can start using more of the new features added to Windows back in 2006.
One of these is a funny control called a "Split Button" which is really a variant form of a Win32 Button control such as the ones that live inside of VB6's intrinsic CommandButton control. However Microsoft hasn't updated VB6 and isn't likely to, so as with so many things we have to take matters into our own hands and dig around under the covers.
SplitButtons.bas is a VB6 static module designed to help implement the additional capability in CommandButtons.
Split Button?
There are problems this might be a good solution for, but probably not as many as you might think upon first look.
A Split Button is a sort of "composite control" like the ComboBox. Here we have a button combined with a dropdown list. When clicked the button acts like a button. When clicked at the right on the "dropdown glyph" (triangle) a list drops down and the user can select a new meaning for the button.
Normally this changes the button Caption to reflect the new meaning, and future clicks should repeat this selected meaning. Making the change from the dropdown list also acts like a click with the new meaning.
![Name: sshot1.png
Views: 38
Size: 14.0 KB]()
Changing the first button
![Name: sshot2.png
Views: 46
Size: 18.5 KB]()
A few buttons later, changing the button at the bottom
of the Form, note the overhang
For whatever reason Microsoft did not build the dropdown list into the enhanced Button control. They just provide some plumbing that allows you to tie a popup menu to the control yourself.
This means you could put all sorts of weird stuff into that menu and have selection do all sorts of crazy things. But it is probably going to be far better for your users if you stick to the "prescribed" behavior of Split Button controls.
Requirements
Windows Vista or later. Rumored to also work in XP (SP2? SP3?) but Vista is documented as the minimum.
Programming Requirements
This will not do anything at all for you unless your program has an application manifest that selects the Common Controls 6.0 assembly.
And when you do that you really want to use a Sub Main() as your "startup object" that loads a couple of libraries in the correct sequence (see the demo). If you fail to do this your programs might work sometimes and then mysteriously crash other times. I don't know why this isn't consistent, but it does lead to some quirky programs floating around out there. Better to just do the load sequencing and be safe.
See the comments in the demo code. They help explain some extra steps required to use Split Buttons in a UserControl too.
IDE Testing
To have the style change make any sense for testing VB6.EXE will need an application manifest.
I don't normally like to work this way because it can mess up a few things, for example some of the "list" properties of control in the Properties Pane of the IDE.
Manifest caching can also make it annoying to try to use file manifests: a change may not show until next reboot. I've had better luck embedding a manifest in VB6.EXE, but I have a nice tool for this. Your mileage may vary.
Testing the Demo
Assuming you have VB6 installed on Vista or later you can just unzip the archive, open the .VBP file, and compile the program without trying to run it within the IDE. Then exit the IDE and run the compiled EXE.
Some Remarks
While a lot of people forget (never knew?) this, the Windows keystroke to "drop" a list (ComboBox, etc.) is the F4 key. From there the user can up/down arrow to choose a list item and Enter to select it. Since Microsoft didn't seem to implement that either, SplitButtons.bas goes ahead and does so. Sadly this makes the code slightly more complex than it might otherwise need to be, and we have to subclass two windows.
Oh well! At least the mouseless will appreciate the effort.
I have noticed that some people implement the dropdown/popup a little differently, indenting the menu to the right 120 to 180 twips or so. Feel free to change this, it should be simple enough.
I think the demo's buttons are a little tall myself, but you can just size those in design mode as with any CommandButton.
One of these is a funny control called a "Split Button" which is really a variant form of a Win32 Button control such as the ones that live inside of VB6's intrinsic CommandButton control. However Microsoft hasn't updated VB6 and isn't likely to, so as with so many things we have to take matters into our own hands and dig around under the covers.
SplitButtons.bas is a VB6 static module designed to help implement the additional capability in CommandButtons.
Split Button?
There are problems this might be a good solution for, but probably not as many as you might think upon first look.
A Split Button is a sort of "composite control" like the ComboBox. Here we have a button combined with a dropdown list. When clicked the button acts like a button. When clicked at the right on the "dropdown glyph" (triangle) a list drops down and the user can select a new meaning for the button.
Normally this changes the button Caption to reflect the new meaning, and future clicks should repeat this selected meaning. Making the change from the dropdown list also acts like a click with the new meaning.
Changing the first button
A few buttons later, changing the button at the bottom
of the Form, note the overhang
For whatever reason Microsoft did not build the dropdown list into the enhanced Button control. They just provide some plumbing that allows you to tie a popup menu to the control yourself.
This means you could put all sorts of weird stuff into that menu and have selection do all sorts of crazy things. But it is probably going to be far better for your users if you stick to the "prescribed" behavior of Split Button controls.
Requirements
Windows Vista or later. Rumored to also work in XP (SP2? SP3?) but Vista is documented as the minimum.
Programming Requirements
This will not do anything at all for you unless your program has an application manifest that selects the Common Controls 6.0 assembly.
And when you do that you really want to use a Sub Main() as your "startup object" that loads a couple of libraries in the correct sequence (see the demo). If you fail to do this your programs might work sometimes and then mysteriously crash other times. I don't know why this isn't consistent, but it does lead to some quirky programs floating around out there. Better to just do the load sequencing and be safe.
See the comments in the demo code. They help explain some extra steps required to use Split Buttons in a UserControl too.
IDE Testing
To have the style change make any sense for testing VB6.EXE will need an application manifest.
I don't normally like to work this way because it can mess up a few things, for example some of the "list" properties of control in the Properties Pane of the IDE.
Manifest caching can also make it annoying to try to use file manifests: a change may not show until next reboot. I've had better luck embedding a manifest in VB6.EXE, but I have a nice tool for this. Your mileage may vary.
Testing the Demo
Assuming you have VB6 installed on Vista or later you can just unzip the archive, open the .VBP file, and compile the program without trying to run it within the IDE. Then exit the IDE and run the compiled EXE.
Some Remarks
While a lot of people forget (never knew?) this, the Windows keystroke to "drop" a list (ComboBox, etc.) is the F4 key. From there the user can up/down arrow to choose a list item and Enter to select it. Since Microsoft didn't seem to implement that either, SplitButtons.bas goes ahead and does so. Sadly this makes the code slightly more complex than it might otherwise need to be, and we have to subclass two windows.
Oh well! At least the mouseless will appreciate the effort.
I have noticed that some people implement the dropdown/popup a little differently, indenting the menu to the right 120 to 180 twips or so. Feel free to change this, it should be simple enough.
I think the demo's buttons are a little tall myself, but you can just size those in design mode as with any CommandButton.