About Programming Microsoft Office Visio 2007 Viewer
Microsoft Office Visio 2007 Viewer is an ActiveX control that enables you to open, view, or print Microsoft Office Visio drawings, even if you do not have Visio 2007. To edit, save, or create a new Visio drawing, you must have Office Visio 2007 installed.
The Viewer provides an application programming interface (API) that enables solution developers to perform the following tasks:
- Load and unload Visio drawings
- Select shapes
- Follow hyperlinks
- Display Viewer dialog boxes to the user
- Customize the size and position of the Viewer window
- Customize the user interface by changing foreground and background colors and displaying or hiding the grid and the scrollbars
- Control the color and transparency of layers in the drawing
- Control the color and visibility of reviewer markups (comments)
- Customize the toolbar by adding or removing buttons
- Respond to user actions in the Viewer interface
You can place a Viewer control in a Windows form or on a Web (HTML) page, and you can use various programming environments to program the Viewer.
You can use Visual Basic 6.0 to instantiate the Viewer control in various containers, such as a Windows form, for example. First, you must get a reference to the Viewer API.
Use the following procedure to get a reference to the Viewer API in a Visual Basic 6.0 project.
To get a reference to the Viewer API in a Visual Basic 6.0 project
- Open Microsoft Visual Basic 6.0. In Microsoft Vista, right-click the program shortcut and then click Run as administrator.
- In Visual Basic 6.0, open a new Standard EXE project.
- In your project, right-click the Toolbox, click Components, select Microsoft Visio Viewer 12.0 Type Library, and then click OK.
- Before you compile your code, on the Project menu, click [your project name] Properties.
- On the Make tab, verify that Remove information about unused ActiveX controls is not selected.
The following code shows how to instantiate the Viewer in a form in Visual Basic 6.0. It creates a Viewer control, displays the Properties and Settings dialog box, sets the location, size, and visibility of the control within the form, and loads a document named "MyFile.vsd" into the control.
Add the following code to the project you created.
You can use the Viewer control to embed a Visio drawing into a Web page, by manually inserting tags and parameters in the source code of the page. To write the source code, you can use a text editor, such as Notepad, or any other application that creates Web pages, such as Microsoft Expression Web or Microsoft SharePoint Designer.
You can set any of the properties of the Viewer by using the PARAM tag, as shown in the following sample code, which sets the Src property of the Viewer.
Notice that because the Viewer is an ActiveX control, its behavior is influenced by Internet Explorer security settings.
The following code shows how to open a Visio drawing file in a Viewer control on a Web page. It sets the height and width of the Viewer control on the page and loads a source document into the control.
Copy the code into a file in a text editor, and save the resulting document as an HTM file. The Visio document "SalesData.vsd" referenced by the Src parameter should be in the same folder as the HTM file.
You can use managed code to instantiate the Viewer control in various containers, such as a Windows form. First, you must get a reference to the Viewer API.
Use the following procedure to get a reference to the Viewer API in a Visual Studio 2008 project.
To get a reference to the Viewer API in a Visual Studio project
- On the Start menu, point to All Programs, click Accessories, and then click Command Prompt to open the Command Prompt window.
- In the Command Prompt window, navigate to the Microsoft Office/Office 12 subfolder of the Program Files folder.
- Copy the file VViewer.dll to a folder location to which you have permission to write new files, for example, your user folder.
- Close the Command Prompt window, and then open the Visual Studio 2008 Command Prompt window. (On the Start menu, point to All Programs, click Microsoft Visual Studio 2008, click Visual Studio Tools, and then click Visual Studio 2008 Command Prompt).
- In the Visual Studio 2008 Command Prompt window, navigate to the folder to which you copied the Viewer DLL file.
- In that folder, type "AxImp.exe vviewer.dll" to generate several files, including AxVisioViewer.dll.
- In Visual Studio 2008, open a new Windows Forms Application project.
- In your project, on the Project menu, click Add Reference, and then click Browse.
- Browse to the folder where you created the AxVisioViewer.dll file, select that file in the list, and then click OK.
In your Visual Studio project, in the Form1.cs file, add the following code to instantiate the Viewer control, set some of its properties, and load a test file into the control. This code assumes that you have a Visio file named "test.vsd" in your Documents folder, at the path shown. Modify the path and file names accordingly for your computer.