Visio Guy

Visio Discussions => Programming & Code => Topic started by: llmmnnoo2002 on April 29, 2008, 01:33:31 PM

Title: Can't add anchored window
Post by: llmmnnoo2002 on April 29, 2008, 01:33:31 PM
Hello,

I am writing a C# Visio COM-AddIn for visio 2007 using Visual Studio 2005.

I am trying to add an anchored window using the Windows.Add method, but I can only choose VisWinTypes.visStencilAddon as a type. All other types always result in the exception "Invalid window type for this action".

When the type is VisWinTypes.visStencilAddon, a window does appear (no exception).

The code that throws the exception is

Window visioWindow = vsoApplication.Windows.Add(
VisWindowStates.visWSAnchorLeft |
VisWindowStates.visWSAnchorAutoHide |
VisWindowStates.visWSVisible,
VisWinTypes.visAnchorBarBuiltIn
,55, 55, 100, 100, null, null, null);

I have tried many variations with the argumets, but when VisWinTypes is not visStencilAddon, the exception occures.
It is possible that the problem is not with the VisWinType, but with the other argumets. I just don't know.

Any ideas ?

Thanks
Title: Re: Can't add anchored window
Post by: Visio Guy on April 29, 2008, 01:45:45 PM
Hi "I"...

The anchor windows need to anchor to a document window, so I believe you are still one level too high. Try something like this:

Visio.Application.Windows(1).Windows.Add(...)
Visio.Application.ActiveWindow.Add(...)

Your code was trying to add a window to the application's window - ie: the main Visio window.

Does that make any sense?
Title: Re: Can't add anchored window
Post by: llmmnnoo2002 on April 30, 2008, 06:18:28 AM
It works! the exception is no longer there and an anchored window does appear.
Many thanks for the quick reply.