How to Access Commandbars Collection from Delphi

K

Kiran

Hi,
I want to customize the Visio 2002 UI using Delphi 6. I am trying to
customize it using the CommandBars collection (as the msdn says it offers
more versatile control). As the Type library does not expose a CommandBars
collection as the VBA code shows, I am not able to get far. Can anyone help
me a bit. If I have to ask this on a different news group, you could please
tell me that as well.
Thanks and best regards,
Kiran
 
G

Graham Wideman \(Visio MVP\)

Kiran:

I use Delphi a lot with Visio... very satisfactory. The short answers are:

a) You need to import the type library for the MS Office DLL (I think it's
MSO.DLL... and there are different versions, like 10 and 11 for Office XP
and 2003).

b) I'd steer you towards using the UIObject (CustomMenubars etc) rather than
CommandBars. Visio's UI is specified by the UIObject data, and Visio uses
CommandBars as a service for rendering the UI. If your code interacts
directly with CommandBars, it mostly works, but there are situations,
notably when a user switches documents, that your CommandBar modifications
are lost. Hence asseting your UI upstream is a better policy.

Graham

--
 
K

Kiran

Hi,
I had problems getting it right with Eugene's suggestion because, I
used index starting with 0. The commandbars collection apparently
starts from 1. I am putting some code below, using which I
successfully iterated through the collection.
Thanks and Best Regards,
and a special thanks to Eugene, and Graham for your various replies
and postings.
/Kiran

procedure TfrmVisOle.Iterate;
var
ICmdBars: Office_TLB.CommandBars;
ICmdBar: Office_TLB.CommandBar;
i: Integer;
begin
VisioApp.CommandBars.QueryInterface(Office_TLB.Commandbars,
ICmdBars);
ICmdBar := ICmdBars.Item[visUIObjSetCntx_DrawOleObjSel];
if ICmdBar <> nil then
begin
for i := 1 to ICmdBar.Controls.Count do
if ICmdBar.Controls.Caption = 'Custom Properties...' then
begin
cmdBarBtn :=
Office_TLB.CommandBarButton(ICmdBar.Controls.Control);
end;
end;
for i := 1 to ICmdBar.Controls.Count do
begin
{Get the CommandBars Names}
lb.Items.Add(ICmdBars.Item.Name + ' ' +
ICmdBars.Item.Context);
{Get the CommandBarControls' caption}
lb.Items.Add(ICmdBar.Controls.Caption);
end;
end;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top