Stencil won't open in ActiveX control

P

Pete

I am using the Visio ActiveX control on a form. When the program
starts, I call the following code to open a stencil:

Visio.Document stencil = visDocuments.OpenEx(
Application.StartupPath + @"\MyStencil.vsx", (short)
Visio.VisOpenSaveArgs.visOpenRO + (short)
Visio.VisOpenSaveArgs.visOpenDocked );

This used to work fine. However, at one point I was working in Debug,
running the app, when I detached the stencil and left it floating.
Then I closed the program. Ever since, when I start the program (in
Debug or the Release version installed on a target machine), the
stencil will not open. If I manually call OpenEx and open the
stencil, it appears in the floating window the same as how I left it.
I have tried re-docking the stencil pane and then closing the program,
which works for the rest of my Visual Studio session, but if I close
VS down and start it up again, the behavior repeats itself, with no
stencil opening.

I figure there must be a Registry setting that has gotten stuck, but I
haven't been able to find it. Mai-Lan, can you help?

Pete
 
S

Scott Metzger

I have observed the same behavior. It seems to ignore the visOpenDocked.

I think its a bug.

For now I am making sure I save the drawing with the stencil docked and
then when I open the drawing it automatically opens the stencil docked.
 
M

Mai-lan [MS]

Pete, if you're just trying to fix up the floating stencil state in the
client, Scott's exactly right -- you should be able to open the file in
Visio, redock the stencil, and save the drawing again. That should solve
your problem. The drawing saves the stencil state with it.

If you're trying to do this programmatically, use the WIndowStateProperty to
redock a stencil that's floating:

Private Sub Command1_Click()

Dim vsoMainWindow As Object

Dim i As Integer





VisioDC.Src = "C:\Test.vsd"

Set vsoMainWindow = VisioDC.Window.Application.Windows(1)

For i = 1 To vsoMainWindow.Windows.Count

vsoMainWindow.Windows(i).WindowState = visWSAnchorLeft

Next i



End Sub

Thanks,
Mai-lan
 
M

Mai-lan [MS]

By the way, if you use the visWSDockLeft constant, you could dock the
floating stencil window versus anchoring it (which is what my example shows
below)...

Mai-lan
 
S

Scott Metzger

Ok, the following fails to 'dock' the stencil and gives me a run time
error "This operation cannot be performed while doing in place editing."

void CVisio2003ReadDlg::OnBnClickedLoadstencil()
{
CVDocument myDocument(MyVisio.get_Document());
CVApplication myApplication(myDocument.get_Application());
CVDocuments myDocuments (myApplication.get_Documents());

myDocuments.OpenEx("C:\\Documents and Settings\\yi010505\\My
Documents\\Icon\\Demo.vss",
visOpenRO);
//visWSAnchorLeft);
// visOpenDocked);

CVWindows myWindows (myApplication.get_Windows());
short numWindows = myWindows.get_Count();
for (short i=1; i<=numWindows; i++)
{
CVWindow myWindow(myWindows.get_Item(i));
//myWindow.put_WindowState(visWSDockLeft);
// visWSDockLeft undefined and couldn't find it in the help
myWindow.put_WindowState(visWSAnchorLeft);
}
}

I get the error when calling put_WindowState.
In addition visWSDockLeft is undefined and when I did a search it in the
Visio Developers Help nothing was found.

Thanks,
Scott Metzger
 
M

Mai-lan [MS]

Hi, Scott: The main issue stems from the use of Application.Windows. You'll
need to use Application.Windows[1].Windows because with the stencil pane,
you're working with the windows collection for the window object. A second
thing to modify: instead of setting the window states to AnchorLeft, you
need to set them to DockedLeft, which looks more like the default Visio
behavior. Here's some C# code that demonstrates what it should look like:
private void button1_Click(object sender, System.EventArgs e)

{

Visio.Document myDocument = axDrawingControl1.Document;

Visio.Application myApplication =

axDrawingControl1.Window.Application;

Visio.Documents myDocuments = myApplication.Documents;

//Open Basic Shapes.vss

myDocuments.OpenEx("Basic Shapes.vss",

(short) Visio.VisOpenSaveArgs.visOpenRO);

Visio.Windows myWindows = myApplication.Windows[1].Windows;

Visio.Window myWindow = null;

short numWindows = myWindows.Count;

for(short i = 1; i <= numWindows; i++)

{

myWindow = myWindows;

myWindow.WindowState =

(short) Visio.VisWindowStates.visWSDockedLeft;

}

}

Thanks,
Mai-lan
 
S

Scott Metzger

Thanks, that worked. Ok, now for the next question. Visio will
'remember' how the stencil is viewed. However, the Drawing Control does
not remember how a stencil is viewed. It always comes up "Icons Only".
How can I change the Stencil View to "Icons and Names"?

Thanks,
Scott Metzger

btw here is the C++ Code..
#define visWSDockedLeft 0x1
void CVisio2003ReadDlg::OnBnClickedLoadstencil()
{
CVDocument myDocument(MyVisio.get_Document());
CVApplication myApplication(myDocument.get_Application());
CVDocuments myDocuments (myApplication.get_Documents());

myDocuments.OpenEx(
"C:\\Documents and Settings\\yi010505\\My Documents\\Icon\\Demo.vss",
visOpenRO);

CVWindows myTopWindows (myApplication.get_Windows());
CVWindow myTopWindow(myTopWindows.get_Item(1));
CVWindows myWindows(myTopWindow.get_Windows());
short numWindows = myWindows.get_Count();
for (short i=1; i <=numWindows; i++)
{
CVWindow myWindow(myWindows.get_Item(i));
myWindow.put_WindowState(visWSDockedLeft);
}
}
 
P

Pete

Scott,

I noticed that too, but got around it by creating a method that would
set the stencil appearance properties. I set the stencil to display
icon and name, and get rid of the Shape Search window. It's too bad
that there is not an easy way in the object model to access these
properties, but using C#, I had to make a class called
OleCommandTarget to execute Visio commands that don't have Automation
equivalents:

/// <summary>
/// Send a command to the Visio drawing control that sets stencil
display to
/// show icons and names, and hides the ShapeSearch section.
/// </summary>
private void SetStencil()
{
// Declare constants from the Visio flags
const UInt32 VISCMD_STENICONANDNAME =
(UInt32)Visio.VisUICmds.visCmdStenIconAndName;
const int VISWINID_SHAPESEARCH =
(int)Visio.VisWinTypes.visWinIDShapeSearch;
IOleCommandTarget cmdt = (IOleCommandTarget)visioCtrl.GetOcx();

try
{
// Send an OLE command to display masters with the icons and names
Guid CLSID_Application = new Guid("{0x00021A20, 0x0000, 0x0000,
{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}");
cmdt.Exec(ref CLSID_Application, VISCMD_STENICONANDNAME, 0, null,
null);

// Get the ShapeSearch window and hide it
VisApp.ActiveWindow.Windows.get_ItemFromID(VISWINID_SHAPESEARCH).Visible
= false;
}
catch(System.Runtime.InteropServices.COMException ex)
{
throw new ITGException(string.Format(ITGResource.GetMessage("COMException",
Utilities.ResourceFileName, this.GetType().Assembly)), ex);
}
}


Good luck with your project, by the way. I tried going down the route
you are now taking for months, but gave up and just decided to use the
ActiveX control and require clients to have Visio 2003.

Pete
 
S

Scott Metzger

Pete said:
Scott,

I noticed that too, but got around it by creating a method that would
set the stencil appearance properties. I set the stencil to display
icon and name, and get rid of the Shape Search window. It's too bad
that there is not an easy way in the object model to access these
properties, but using C#, I had to make a class called
OleCommandTarget to execute Visio commands that don't have Automation
equivalents:

Thats pretty ugly. Anyone have a better way?
Good luck with your project, by the way. I tried going down the route
you are now taking for months, but gave up and just decided to use the
ActiveX control and require clients to have Visio 2003.

Thanks. Thats actually what I am doing. Because I am using MFC C++ and
there are no 2003 C++ examples and the 2003 SDK is not available yet
everything is hit or miss. I am sure things would go much smoother if I
were using VB or C#. But I am adding this functionality to an existing
program so that is not viable.

Thanks,
Scott
 

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