M
Michael Berryman
Hi all. I'm fairly new to COM Programming with Visio, so bear with
me.
Here's the situation: When the user loads Visio, they have the option
to attach toolbars to any given document via customize...attach. This
allows the user to in effect create multiple instances of a custom
toolbar i'm programatically including in Visio (or any custom toolbar
period). The original toolbar is at the Application level, while the
subsequently added toolbars are at the Document level, as I understand
it.
This is bad.
So, what I'd like to do is somehow detect if there is more than one
instance of the custom toolbar in effect, and if so, delete all but
one.
Here's how i'm going about this:
I'm catching the WindowActivated event from visio (in this event, I
update my custom toolbar based on the document) and attempting to
check the Toolbars list.
This is the snipet of code where i'm trying to get the toolbars list.
pApp is passed in via the event.
CComVariant cvDummy(0);
CComVariant cvHold;
CComDispatchDriver ccdApp(pApp);
HRESULT hr = ccdApp.GetPropertyByName(L"CustomToolbars", &cvHold);
CComDispatchDriver ccdUIObj(cvHold.pdispVal);
hr = ccdUIObj.GetPropertyByName(L"ToolbarSets", &cvHold);
CComDispatchDriver ccdToolbarSets(cvHold.pdispVal);
hr = ccdToolbarSets.GetPropertyByName(L"Count", &cvHold);
int nCount = (int)cvHold.lVal;
for (int nCnt = 0; nCnt < nCount; nCnt++)
{
CComVariant cvID(nCnt);
hr = ccdToolbarSets.Invoke1(L"Item", &cvID, &cvHold);
if (SUCCEEDED(hr))// if hr == S_OK
{
// will never get in here.
}
}
it works fine up until I'm trying to get the item property of
ToolbarSets. Despite returning a valid number when the Count property
is obtained (0x00000010), every time I attempt to get
ToolbarSets.Item(nCnt), hr equates to 0x80020003 Member not found.
The perplexing part of this is that I can go into the VB editor
through Visio and run this:
? Application.CustomToolbars.ToolbarSets.Item(IntegerLessThanCount)
and get a return. Furthermore, I can run
? Application.CustomToolbars.ToolbarSets.Item(0).Toolbars.Item(16)
and get the custom toolbar I'm looking for.
Anyone have any idea of why this is working in VB but not VC++? Is it
my code, or something really wacky?
Thanks!
me.
Here's the situation: When the user loads Visio, they have the option
to attach toolbars to any given document via customize...attach. This
allows the user to in effect create multiple instances of a custom
toolbar i'm programatically including in Visio (or any custom toolbar
period). The original toolbar is at the Application level, while the
subsequently added toolbars are at the Document level, as I understand
it.
This is bad.
So, what I'd like to do is somehow detect if there is more than one
instance of the custom toolbar in effect, and if so, delete all but
one.
Here's how i'm going about this:
I'm catching the WindowActivated event from visio (in this event, I
update my custom toolbar based on the document) and attempting to
check the Toolbars list.
This is the snipet of code where i'm trying to get the toolbars list.
pApp is passed in via the event.
CComVariant cvDummy(0);
CComVariant cvHold;
CComDispatchDriver ccdApp(pApp);
HRESULT hr = ccdApp.GetPropertyByName(L"CustomToolbars", &cvHold);
CComDispatchDriver ccdUIObj(cvHold.pdispVal);
hr = ccdUIObj.GetPropertyByName(L"ToolbarSets", &cvHold);
CComDispatchDriver ccdToolbarSets(cvHold.pdispVal);
hr = ccdToolbarSets.GetPropertyByName(L"Count", &cvHold);
int nCount = (int)cvHold.lVal;
for (int nCnt = 0; nCnt < nCount; nCnt++)
{
CComVariant cvID(nCnt);
hr = ccdToolbarSets.Invoke1(L"Item", &cvID, &cvHold);
if (SUCCEEDED(hr))// if hr == S_OK
{
// will never get in here.
}
}
it works fine up until I'm trying to get the item property of
ToolbarSets. Despite returning a valid number when the Count property
is obtained (0x00000010), every time I attempt to get
ToolbarSets.Item(nCnt), hr equates to 0x80020003 Member not found.
The perplexing part of this is that I can go into the VB editor
through Visio and run this:
? Application.CustomToolbars.ToolbarSets.Item(IntegerLessThanCount)
and get a return. Furthermore, I can run
? Application.CustomToolbars.ToolbarSets.Item(0).Toolbars.Item(16)
and get the custom toolbar I'm looking for.
Anyone have any idea of why this is working in VB but not VC++? Is it
my code, or something really wacky?
Thanks!