J
Josef Meile
Hi,
I'm trying to disabling the "Cut" (CTRL-X) shortcut in a Visio 2003 addon
written in C#; however it doesn't works.
I rewrote this VBA Code:
Visio2000: How to Bind a Custom Accelerator Key for a Custom Menu to a
Specific Drawing Window
http://support.microsoft.com/?scid=kb;en-us;281504&x=7&y=17
into C#:
Visio.UIObject visioUI = null;
if (VisioDocument.CustomMenus == null)
visioUI = CExeAddon.VisioApp.BuiltInMenus;
else
visioUI = VisioDocument.CustomMenus;
Visio.AccelTableClass vsoAccelTable =
(Visio.AccelTableClass)visioUI.AccelTables.get_ItemAtID(drawingMenuId);
Visio.AccelItemsClass vsoAccelItems =
(Visio.AccelItemsClass)vsoAccelTable.AccelItems;
Visio.AccelItemClass vsoAccelItem;
//This fails
//IEnumerator AccelEnum = vsoAccelItems.GetEnumerator();
// GetEnumerator() has two overrides, so, I tried both of them:
//This fails
//IEnumerator AccelEnum = ((Visio.IVAccelItems)vsoAccelItems).GetEnumerator();
//And this as well
IEnumerator AccelEnum = ((IEnumerable)vsoAccelItems).GetEnumerator();
while (AccelEnum.MoveNext())
{
vsoAccelItem = (Visio.AccelItemClass)AccelEnum.Current;
if (vsoAccelItem.CmdNum == (short)Visio.VisUICmds.visCmdUFEditCut)
{
vsoAccelItem.Delete();
break;
}
}
VisioDocument.SetCustomMenus(visioUI);
It should work; however, I'm getting the following exception as soon as the
GetEnumerator() method is called:
System.InvalidCastException: QI for IEnumVARIANT failed on the unmanaged
server.
at
System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler.MarshalNativeToManaged(IntPtr pNativeData)
at Microsoft.Office.Interop.Visio.AccelItemsClass.GetEnumerator()
How should I do this in C#?
Thanks in advanced.
Best regards
Josef
I'm trying to disabling the "Cut" (CTRL-X) shortcut in a Visio 2003 addon
written in C#; however it doesn't works.
I rewrote this VBA Code:
Visio2000: How to Bind a Custom Accelerator Key for a Custom Menu to a
Specific Drawing Window
http://support.microsoft.com/?scid=kb;en-us;281504&x=7&y=17
into C#:
Visio.UIObject visioUI = null;
if (VisioDocument.CustomMenus == null)
visioUI = CExeAddon.VisioApp.BuiltInMenus;
else
visioUI = VisioDocument.CustomMenus;
Visio.AccelTableClass vsoAccelTable =
(Visio.AccelTableClass)visioUI.AccelTables.get_ItemAtID(drawingMenuId);
Visio.AccelItemsClass vsoAccelItems =
(Visio.AccelItemsClass)vsoAccelTable.AccelItems;
Visio.AccelItemClass vsoAccelItem;
//This fails
//IEnumerator AccelEnum = vsoAccelItems.GetEnumerator();
// GetEnumerator() has two overrides, so, I tried both of them:
//This fails
//IEnumerator AccelEnum = ((Visio.IVAccelItems)vsoAccelItems).GetEnumerator();
//And this as well
IEnumerator AccelEnum = ((IEnumerable)vsoAccelItems).GetEnumerator();
while (AccelEnum.MoveNext())
{
vsoAccelItem = (Visio.AccelItemClass)AccelEnum.Current;
if (vsoAccelItem.CmdNum == (short)Visio.VisUICmds.visCmdUFEditCut)
{
vsoAccelItem.Delete();
break;
}
}
VisioDocument.SetCustomMenus(visioUI);
It should work; however, I'm getting the following exception as soon as the
GetEnumerator() method is called:
System.InvalidCastException: QI for IEnumVARIANT failed on the unmanaged
server.
at
System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler.MarshalNativeToManaged(IntPtr pNativeData)
at Microsoft.Office.Interop.Visio.AccelItemsClass.GetEnumerator()
How should I do this in C#?
Thanks in advanced.
Best regards
Josef