Solved

CommandBar enhancements in VB Add-Ins - 1500 Points

Posted on 2001-06-15
15
1,556 Views
Last Modified: 2007-11-27
I would like to use the full range of Add-In CommandBar features which are only partially implemented in Add-Ins under VB6.

Since this is a poorly documented area in the MSDN, and very few people are building add-ins (judging by the limited number of relevent questions on EE) I will provide a bit of back ground.

VB Add-Ins and Add-Ins for Microsoft Office (Word, Excel, etc.) allow for programmer defined CommandBars which are similar to VB Toolbars but appear to be implemented differently.

To create them in a VB Add-In we include a reference to Microsoft Office 8.0 Object Library (I'm using VB6 with Office 97 under Win 98SE) along with the Microsoft Visual Basic 6 Extensibility reference.

The CommandBar theoretically provides for a large variety of different button types which we see implemented in the standard VB IDE and the Office suite.  These are enumerated and can be seen with the Object Browser under the Office object MsoControlType key.  In practice, Microsoft restricts the programmer to 3 button types (at least thats all I have been able to implement):
msoControlButton: a basic button with a 16x16 bitmap button face
msoControlPopup: a text caption  with a down arrow (no optional image as far as I can tell)
msoControlComboBox: a standard drop-down combo

An example of one I would dearly love to implement is msoControlSplitButtonMRUPopup.  This is used in the VB IDE Form Editor Toolbar with the "Align", "Center", etc. buttons.

As for what I would specifically like to do:
1) Implement the msoControlSplitButtonMRUPopup style button (or at least an image and a down arrow without the split), and
2) Create a VB "look-alike" button/bar customization mechanism (what you see and can do when you right click an IDE toolbar, select "Customize...", and the "Commands" Tab).

The latter requires drag/drop of buttons, bar position indicators (where button will be dropped), a selection box around the currently selected button, etc.

Full points will be awarded only for "Full Code" solutions (or links to same).
In case of partial solutions - I will award 500 points for the first (msoControlSplitButtonMRUPopup implementation), and 1000 points for the second.

I don't care how it is implemented (within reason) but would prefer it be the "natural" extension of the capabilities that MS gave us.  I.E what they are clearly using but have chosen not to document.  The next best solution would be the ability to subclass or hook the CommandBar and do a "user drawn" CommandBar.  Possibly acceptable solutions could include timer driven "hacks" so long as they don't consume a lot of cpu resources and are flicker free.  Unacceptable solutions are those that require Commercial software such as Desaware SpyWorks.

For a "quick start" simple Add-In" sample see Planet Source "Track Code Changes"
(http://www.planet-source-code.com/xq/ASP/txtCodeId.7005/lngWId.1/qx/vb/scripts/ShowCode.htm)
This sample uses a single button on a standard VB IDE CommandBar.  In my case I want a custom multi-button CommandBar, but the basic Add-In techniques are the same.

Note that CommandBars have standard window handles (hWnd) just like VB Toolbars so we have at least that much to work with.  

Some things I've tried, but couldn't get to work (which doesn't mean they won't - maybe I screwed up):

Given the possibility (fairly remote I think) that the CommandBars use ComCtl32.Dll (as do VB Toolbars), I started with a simple example from VBNet (http://www.mvps.org/vbnet/) "Changing a VB Toolbar to a Rebar-Style Toolbar".  This sample uses ComCtl32.Dll and the API to modify VB toolbar styles.  When I used a CommandBar hWnd I got back a "0" response to the TB_GETSTYLE message so I abandoned this possibility.

Toolbar sub-classing: vbAccelerator (http://vbaccelerator.com/) contains numerous samples of "user drawn" controls (including VB toolbars) using the authors SSubTmr6.DLL subclasser. With this particular subclasser (and all freeware ones I know of) you are limited to subclassing controls that are part of your VB program.  When I attempted to subclass a CommandBar I get the SSubTmr6 error message "Can't modify external window"

Thanks for any help.  Lets see if we can make some advances in this poorly documented and under-utilized capability.

Bob Hamilton

(Why won't EE let me post greater than 300 points? - no points for an answer to this - I know it could be done in the past)
0
Comment
Question by:bhamilto
15 Comments
 
LVL 4

Expert Comment

by:beckingh
Comment Utility
<listening>

I am creating a VB Add-in as well and the lack of documentation is extremely frustrating.

Do you have any other links to quality resources?

0
 
LVL 2

Author Comment

by:bhamilto
Comment Utility
beckingh,

Pretty slim pickings.  ow about you?

I've found the odd thing for certain types of Add-Ins.  What do you need to know? What type of Add-In are you trying to build?

I've got two books on the subject (both now out of print).  One is published by O'Reilly: "Developing Visual Basic Add-Ins" by Steven Roman.  It's good on the basics but I've already gone far beyond in the UI area.  

Another is "Creating Visual Basic 5 Add-Ins" by Swartzfager which was twice the price and half the value.  It does have a lot more detailed examples than the O'Reilly book and may be worthwhile if one comes close to your app.

Amazon lists a total of 4 books on the subject: the 2 above, and 2 new ones that aren't yet in print.  It will be interesting to see if the new ones unlock any secrets.

Good luck - Bob
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
>1) Implement the msoControlSplitButtonMRUPopup style button (or at least an image and a down arrow without the split)

Popup
     Child 1
     Child 2
     
For popup image, Popup uses .ID of its child buttons.

If you want image to appear on the Popup, you must use EXISTING BUILT-IN FACES for child buttons and child button .Id must be = .FaceID

Let me know if this limitation is OK, and if you want code for that.
I'll also add a preview of existing faces.
0
 
LVL 2

Author Comment

by:bhamilto
Comment Utility
ameba,

I'm not sure I understand wat you are saying.

I know how to implement a popup (msoControlPopup)and its children (menu items, with or without images on the menu items).

You don't have to use standard button faces BTW. If you put a non-standard face on the clipboard, you can use the CommandBarControl object PasteFace method to incorporate it in the control (either a button or a menu item).  This method is undocumented for the CommandBarControl object as far as I know (it doesn't show in the Object Browser).

As far as I know a popup button (implemented as a CommandBarControl object of type msoControlPopup) can only have a text caption but not a button face.  Are you telling me that you know how to get a face image on a popup button (with no caption, but retaining the down arrow)?  If so that would be an acceptable answer to my question.  I would prefer a button with type msoControlSplitButtonMRUPopup, but a button with an image, an arrow to te right of the image, and no caption is the next best thing.

I have program that generates all of the stock button faces, but thanks for the offer.

Bob
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
By Popup I meant Type:=msoControlSplitButtonMRUPopup
If you use PasteFace, it won't work OK - popup won't show the right image.

I don't know if those BUILT-IN FACES are enough for you.
This is zip: http://www.geocities.com/ameba_vb/temp/pop01.zip
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
Please, use right-click and "Save Target As" to download zip file.
0
 
LVL 2

Author Comment

by:bhamilto
Comment Utility
ameba,

Thanks for the code. It ran fine and ported nicely to my custom CommandBar.
My problem was in not setting the Id correctly when the button was added.

Having played with the code, I now understand your comment.
It is a restriction having to use the built in faces in my menu items.  
I was hoping to be able to use custom faces.

Is there a way around this? Two things come to mind:

1) Is there any way of appending additional buttons to the built in faces?

2) Do any of the other popup/dropdown control types allow me to use custom faces?
I don't mind programmatically setting the face to a custom button face reflecting the MRU.
I can't get any of the following to operate - probably because I'm not adding them right (like I screwed up the MRU popup):
msoControlButtonDropdown
msoControlGenericDropdown      
msoControlGraphicDropdown      
msoControlGraphicPopup          
msoControlSplitDropdown
What are these and how do I use them?
Will one of them do the job with a bit of code to set the button face to the MRU?

I feel that I owe you points (and an "A") because you DID answer my question.
It's my problem that I wasn't specific enough in my question.  
Would appreciate any help in getting the ability to use custom faces tho.

Many thanks - Bob

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Author Comment

by:bhamilto
Comment Utility
ameba,

Missed 1 in the list of "unknowns":
msoControlSplitButtonPopup

Thanks - Bob
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
>What are these
There is a 'preview page' in Word Help. To find that page in help file see "Type Property"

how do I use them?
Hmm... I don't have samples.
0
 
LVL 2

Author Comment

by:bhamilto
Comment Utility
ameba,

Thanks for the tip.  The help file reference isn't a lot of "help" since I can't find any implementation details.
Several of the illustrated controls might work, but they are shown only with built-in faces so who knows?

I suspect my best hope is a C++ DLL for subclassing or hooking the WM_DRAWITEM message (or whatever message the CommandBar uses when it wants a repaint of the bar).  I suspect I'd have to resort to this for the CommandBar customization anyway.

Unfortunately my C++ skills are pretty rusty so I think I will add pointers to this question in the C++ section of EE.

In the meantime I said I would give you 500 points for the sample you provided.  Whats the best way to do this since questions now seem to be limited to 300 points?

Thanks - Bob
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
>In the meantime I said I would give
I understand it really wasn't what you expected, and you don't have to give me any points - feel free to delete the question.

>It is a restriction having to use the built in faces in my menu items.  
>I was hoping to be able to use custom faces.

You can have custom faces for children and some built-in fixed image for Popup (by Popup I mean Type:=msoControlSplitButtonMRUPopup)
- to do this, each Child button must have the same Id

It seems it is not possible to add/modify built-in faces.
Checking all toolbars in VB, I found 6 button Types - 0, 1, 3, 4, 10, 14
but it seems it is possible to use only five from Add-In: 1, 3, 4, 10, 14 (msoControlButton, msoControlDropdown, msoControlComboBox, msoControlPopup, msoControlSplitButtonMRUPopup)
.Controls.Add method fails for Type=0 (msoControlCustom)

Your second question
>2) Create a VB "look-alike" button/bar customization mechanism

That 'mechanism' depends on what you use - to imitate the whole thing, you'll have to integrate it with your toolbars (and maybe with dockable forms).

Toolbars provided by mscomctl32.ocx don't have docking. If you want to use that toolbars, there is a Customize method - it allows drag-drop (it has 'Customize' dialog with 2 listboxes).

Office customization allows dragging Menus to toolbar - of course, you won't be able to have that functionality with VB menu system.
0
 
LVL 2

Author Comment

by:bhamilto
Comment Utility
ameba,

I didn't get exactly what I wanted, but I definately learned some useful things.  You were very generous with your time.  

How about if I give you the 300 points for this question and I'll repost the question with some changes?

Thanks - Bob

0
 
LVL 15

Accepted Solution

by:
ameba earned 300 total points
Comment Utility
OK, Bob. I'm glad if it helped. Thank you for the points!
0
 
LVL 2

Author Comment

by:bhamilto
Comment Utility
Thanks ameba
0
 

Expert Comment

by:sdavis2000
Comment Utility
I have come across this thread and would like to know if any of you have example code for using popup type msoControlSplitButtonPopup (or similar) in VBA for Outllook 2000. I have many of the same issues discussed above. An example using VB would suffice.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now