Volume 3: Programming with the Visio Object Model disclaimer


Review: Managing External Data Sets



Download 0.78 Mb.
Page29/36
Date29.01.2017
Size0.78 Mb.
#11974
1   ...   25   26   27   28   29   30   31   32   ...   36

Review: Managing External Data Sets

Questions


  1. What are the three methods of the DataRecordsets object for creating new datarecordsets?

  2. What is different about the datarecordset created using the AddFromXML method?

  3. Where can the connection string be found in the object model?

  4. Where can the command string be found in the object model?

  5. When adding a datarecordset, how is the primary key set?

  6. Which property of the DataConnection object is key to catching errors thrown when a data source cannot be reached?

  7. True or False. When creating and linking shapes using the DropLinked and DropManyLinkedU, the shapes are created and linked at the same time, but a data graphic has to be added as a separate step.

  8. True or False. A shape can be linked to multiple datarecordsets with a single command.

  9. True or False. To link multiple shapes to a single row you can use the Shape.LinkToData method multiple times.

  10. How does a programmer reliably detect when a shape link has been broken, either through programmatic actions or through user actions.

  11. True or False. GetAllRefreshConflicts can be used by the programmer to discover all changes that occur during a refresh operation.

  12. How does the programmer control display of the Refresh Conflicts task pane?

  13. True or False. The DataRecordsetChanged event will fire immediately following the Refresh method.



Answers


  1. Add, AddFromConnectionFile, and AddFromXML

  2. It is a connectionless datarecordset.

  3. It is in the DataConnection object which is part of the DataRecordset object.

  4. The DataRecordset object.

  5. The primary key is set as a separate step from the Add. Use the SetPrimaryKey method of the DataRecordset object.

  6. Set the Timeout property. When the interval is exceeded and error is thrown.

  7. False

  8. False. The LinkToData method must be called once for each datarecordset.

  9. True. This will work, but use the Selection.LinkToData to do it in one step.

  10. Use the ShapeDataLinkDeleted event.

  11. False. This only gives information on conflicts. Use the DataRecordsetChanged event and DataRecordsetChanged object to get additional data on records added or deleted and columns changed, added, or deleted.

  12. vsoDataRecorset.RefreshSettings = visRefreshNoReconciliationUI

  13. False. There can be a time lag between the Refresh and the firing of the event which means code following the Refresh may execute before code in the event procedure. Put any conflict resolution code or code that looks for datarecordset changes inside the event procedure.

Visio Software Development Kit (SDK)


This module covers all aspects of the Visio 2010 SDK. The SDK is made up of code samples, sample applications, tools, and documentation to support developers creating shapes, creating code, and delivering their own custom solutions on Visio.

Note:

At the time of this writing the Visio 2010 SDK was still in beta. Little of the documentation has been updated and some sample files have not been released and therefore are not covered. The reader may find differences between the discussion in the final version when the RTM version of the SDK is released. Hopefully those differences will be minor.



Module Objectives

After completing this module you will be able to:

  • Understand all of the parts that make up the Visio SDK

  • Use the tools delivered with the SDK to aid in manage events and publish solutions

  • Use the sample code from the code library in your own programs

  • Use the sample applications as examples for creating add-ins and add-ons for Visio


Lesson 1: Setup / Overview


The Microsoft® Office Visio® 2010 Software Development Kit (SDK) contains the latest documentation, samples, header files, libraries, and tools that you need to develop custom solutions for Microsoft Office Visio 2010.

Visio SDK 2010 Contents


To open the Visio 2010 SDK, click Start > All Programs > 2010 Microsoft Office Developer Resources > Microsoft Office Visio 2010 SDK.

The Visio 2010 SDK includes:



  • Microsoft Office Visio Code Samples Library. A database of Visio code samples.

In the Code Samples Library, you can select a code item from the tree-view Explorer window, or you can search and select the desired code item from the Search Results tab. You can use the Code Samples Library to view and copy many reusable classes, functions, and procedures.

To open the Code Samples Library, click the Start button, point to Microsoft Office 2010 Developer Resources, then point to Microsoft Office Visio 2010 SDK, and then click Microsoft Office Visio Code Samples Library.



  • Sample applications.   The provided sample applications can be used to experiment and to become acquainted with features. These sample applications are written both to demonstrate aspects of developing on the Visio platform and to be used as a starting point for your custom applications.

  • Tools.   Customization and extensibility tools are provided to increase your productivity and reduce development time. These tools include the Persistent Events, Print ShapeSheet, Solution Publishing, and Event Monitor tools.

The SDK also includes wizards to set up new Visio add-ons and Component Object Model (COM) add-ins in Microsoft Visual C#©, Microsoft Visual Basic® .NET, Microsoft Visual C++® and Microsoft Visual Basic®.

  • Documentation   The documentation includes the full set of Visio references and articles.

You do not need to have the Microsoft Office Visio 2010 application installed on your computer to be able to install the Visio 2010 SDK; however, for selected code samples or tools to run properly, Visio is required.
Locating the SDK Files

By default, the Visio 2010 SDK is installed in the following folder:

C:\Program Files (x86)\Microsoft Office\Office14\visSDK\ for the 32 bit version of the Visio SDK.


To uninstall the SDK at any time

In Control Panel, click Add or Remove Programs, click Microsoft Office Visio 2010 SDK, and then click Remove.

31.Software Requirements for Visio 2010 SDK Tools and Samples


Although you do not need to have Visio 2010 installed on your computer to be able to install the Visio 2010 SDK, the following tools and samples will not run correctly unless the following software dependencies are met.

Table 2. Visio 2010 SDK software requirements for tools and samples

Tool or sample

Software requirements

Persistent Events tool

Visio 2010

Event Monitor tool

Visio 2010

Print ShapeSheet tool

Visio 2010

Visio Solution Publishing tool

Visio 2010

Microsoft Visual Studio 2005 Visio Add-in wizard

Microsoft Visual Studio 2005

Microsoft Visual Studio 2008 Visio Add-in wizard

Microsoft Visual Studio 2008

Microsoft Visual Basic 6.0 Flowchart sample application

Visio 2010

Microsoft Office Excel 2007

Microsoft Office Word 2007 (to embed the drawing into a Word document)


Microsoft Visual Basic .NET Flowchart sample application

Visio 2010

Excel 2007

Word 2007 (to embed the drawing into a Word document)

Microsoft .NET Framework 1.1 or Microsoft .NET Framework 2.0

Visual Studio .NET 2005 or Visual Studio 2008


C# Flowchart sample application

Visio 2010

Excel 2007

Word 2007 (to embed the drawing into a Word document)

Microsoft .NET Framework 1.1 or Microsoft .NET Framework 2.0

Visual Studio .NET 2003 or Visual Studio 2005


C++ Flowchart sample application

Visio 2010

Excel 2007

Word 2007 (to embed the drawing into a Word document)

Visual Studio .NET 2005, Visual Studio 2008, or Visual C++ 6.0 (Service Pack 3 or later)



TreeView sample application

Visio 2010

Microsoft .NET Framework 1.1 or Microsoft .NET Framework 2.0

Visual Studio .NET 2005 or Visual Studio 2008 (to build the sample code)


Office Plan sample application

Visio 2010

Microsoft .NET Framework 1.1 or Microsoft .NET Framework 2.0

Visual Studio .NET 2005 or Visual Studio 2008


Visio 2010 Code Samples Library

Visio 2010

2007 Microsoft Office System





Known Issues and Notes


  • Some sample applications and code samples in the Visio 2010 Code Samples Library require the installation of Microsoft Office applications or Visio 2010 solutions and wizards. See Visio 2010 SDK Samples located in the Samples folder in this SDK for more information about specific requirements.

  • In versions of Visio previous to Visio 2007, Shape Data was called Custom Properties. In the Visio 2010 SDK, these terms are used interchangeably; they both refer to the concept of attaching user data to Visio shapes.

  • In order to compile SDK samples in Visual Studio running on the Microsoft Windows Vista operating system, you must have administrative rights in Visual Studio.

  • Microsoft SQL Express 2005 is available as a free download at the following URL:

http://www.microsoft.com/downloads/details.aspx?FamilyID=220549b5-0b07-4448-8848-dcc397514b41&DisplayLang=en.

32.Documentation


This documentation contains reference material describing the Visio 2010 Automation Interface, the Save as Web Page Interface, the ShapeSheet interface and the XML schema documentation.
Visio 2007 Automation Reference

Provides an overview of Automation in Visio. It includes information about the Visio object model, the Visio type library, and about extending the functionality of Visio with macros, add-ons, and COM (Component Object Model) add-ins. A sample Microsoft Visual Basic for Applications (VBA) macro is also provided. This reference provides details on Visio objects, properties, methods, and events.
Save as Web Page Reference

Provides an overview of using the Save as Web Page API with Microsoft Office Visio 2007. Details about the Save as Web Page methods, objects, enumerations, and properties are provided. There is also an example of a Microsoft Visual Basic example of the Save as Web Page object model.
ShapeSheet Reference

Provides an overview of the ShapeSheet spreadsheet in Visio, including information about working with formulas, strings, date and time values, units of measure, and information about common ShapeSheet tasks, such as adding and deleting ShapeSheet sections and referencing cells from formulas. Details on each section, row, and cell in a ShapeSheet spreadsheet and details on functions you can use in formulas are provided.
XML Reference

Provides an overview of XML for Visio. Detailed information is provided for the XML for Visio schema, inheritance, working with sheets and formulas, geometry, text, loading XML files created outside Visio, round-tripping XML data, embedding custom XML data, units of measure, and errors and warning messages.

33.Containers

Folders Installed with the Visio 2010 SDK


The following table describes the folders that are installed with the Visio 2010 SDK.

Table . Visio 2010 SDK folders

Folder name

Description

\Docs \

References and articles

\Libraries\

Support files

\Samples \

Sample applications that demonstrate how to use the Visio programming model

\Tools \

Development, customization, solution-publishing, and extensibility tools

\Wizards\

Wizards to simplify developing Visio applications



Docs folder

  • visSDK.chm – entry point into help files for Visio 2010 SDK Documentation
Libraries

  • CPP folder – C and C++ files

    • Include

      • AddSink.h – contains the prototype for the event call back function (VISEVENTPROC) along with the class definitions for VEventHandler and CVisioAddonSink.

      • Helpers.h - contains the definitions of helper classes to be used with the wrapper code in Visiwrap.h. You can choose to use no helpers, or non-MFC helpers or MFC-aware helpers.

      • Ivisreg.h - contains helper functions for launching the Visio application.

      • Vaddon.h - contains the definition of a superclass for Visio add-ons.

      • Vao.h - contains definitions that define the interface between Visio and VSLs.

      • Visio.h - this ALWAYS GENERATED file contains the definitions for the interfaces

      • Visio_i.c - this ALWAYS GENERATED file contains the IIDs and CLSIDs

      • Visiwrap.h - contains a set of wrapper classes and their implementations for the Visio automation API

    • Source

      • AddSink.cpp - contains implementation of Visio's Advise Sink event handling.

      • Helpers.cpp - contains the implementation of helper classes to be used with the wrapper code in Visiwrap.h.

      • Ivsireg.cpp - contains helper functions for starting Visio and getting access to the IVisioApplication interface.

      • Vaddon.cpp - provides the entry point for a Visio VSL. It also provides an add-on 'manager' superclass called VAddon. You can use VAddon as the base class for Visio add-ons.

      • Vao.c - This file provides implementations for the routines prototyped in vao.h.

      • Vdllmain.c - contains an implementation of DllMain for Win32 VSL's.

      • Vexe.cpp - implements the standard Windows message loop and window procedure for EXE based VAddon subclasses. It allows VAddon-derived classes to be compiled into an EXE with no additional effort.

  • TypeLib folder – contains the following type library files

    • Visio.tlb – 2010 type library

    • SaveAsWeb.tlb – Visio 2010 Save as Web type library

    • VisOCX.tlb – Visio 2010 Drawing Control type library
Samples

The Samples folder contains the Code Samples Library folder which contains a .chm file with many examples of common tasks done in Visio through automation. Directions are provided on how to copy code directly from the help file into your project.

It also contains three complete projects:



  • FlowChart - shows how to create a Component Object Model (COM) add-in that automates the creation of a flowchart drawing from a Microsoft Office Excel® spreadsheet, uses command bars in the Visio user interface, and publishes the drawing to the Web or to a Microsoft Office Word document. The code is available in C++, C#, VB, and VB .NET.

  • OfficePlan - shows how you can use the Microsoft® Visio® 2010 Drawing Control to create an application that takes advantage of the drawing features of Microsoft Visio 2010 in a Microsoft Windows Form. The sample application can be used to select furniture from an inventory list and plan the space for a conference room or office. The code for this application is in C#.

  • TreeView - shows how to create a hierarchical drawing and its accompanying tree view in Microsoft® Office Visio® 2010. The sample application provides a summary view of a drawing that has many shapes and which therefore can be hard to view on the page. The sample application is a Visio COM add-in, written in Microsoft Visual Basic® .NET.

Note:

The final Visio 2010 SDK is expected to have a new VSTO Add-in Sample Application that uses a "ClickOnce" post-deployment action to install Visio template and stencil files and also samples for API functionality added in Visio 2010.



Tools

This folder contains Help files and for using a set of tools provided with the Visio 2010 SDK:

  • Event Monitor – tool that monitors events that are fired by an instance of Visio and reports events based on options you select in the Event Monitor user interface.

  • Persistent Events - provides a user interface that lets you add persistent events in an active Visio document and modify existing persistent events.

  • Print ShapeSheet - provides a user interface that lets you print ShapeSheet data for one or more shapes, a document, or a page, or lets you print ShapeSheet data for all document styles.

  • Solutions Publishing – tool that provides a user interface that lets you generate entries to insert in the PublishComponent table in a Windows Installer (.msi) file for publishing Visio content.

Note:

Each of these tools is covered in more detail later in this module.



Wizards

The Visio 2010 SDK contains two add-in wizards, one for Visual Studio 2005 and the other for Visual Studio 2008. These wizards create a shell add-on or add-in project in Microsoft Visual Studio® .NET 2003, in Microsoft Visual Basic® .NET, Microsoft Visual C#®, and Microsoft Visual C++®, to help speed the development process and demonstrate suggested practices for developing Visio add-ons or Component Object Model (COM) add-ins.

Note:

This tool is covered in more detail later in this module.


34.TypeLibs Included


The Microsoft® Visio® 2010 Software Development Kit (SDK) provides type libraries for three application programming interfaces (APIs) that Microsoft Office Visio 2010 exposes. The following type libraries are included in the TypeLib folder, the path to which is SDK\Libraries:

Library

Contents

Visio.tlb

Visio type library

SaveAsWeb.tlb

Save as Web type library

VisOcx.tlb

Microsoft Office Visio Drawing Control type library



Visio type library


An overview of the Visio type library was given in the beginning of Volume 3 of this course.

Save As Web type library


The Save As Web interface is not covered in this class, but there is a good example of how to use it provided in the Flowchart sample program in the SDK. The Flowchart sample uses this interface to save Visio drawings as web pages.

Visio Drawing Control type library


The Visio Drawing Control can be used to embed the full functionality of the Visio drawing surface into your applications. You can take advantage of the full Visio object model (API) and you can pick the aspects of the Visio user interface you want to expose to better integrate Visio seamlessly into the user interface of your application.

Use of the Visio Drawing Control will be covered in the next module of this course: Module 5: Visio Drawing Control




35.Changes from Visio 2010 SDK


The following are changes to the SDK since the 2003 version.

36.Visual Studio 2005 and 2008 Add-in Wizards


The Visio SDK installs wizards for creating Visio add-on projects in Microsoft Visual Studio 2005 and Microsoft Visual Studio 2008. These Wizards let you set up new Visio add-on projects in Microsoft Visual Basic .NET, Microsoft Visual C#, and Microsoft Visual C++, and create corresponding setup programs to install add-ons. Once you have used the wizard to create a Visio project, you can explore the project code and settings to learn more about how Visio add-ons should work.

visualstudiowizard

Microsoft Visual Studio 2010 also includes wizards to generate Visio 2010 VSTO add-in projects. The Visio SDK is not required to use these wizards.



clip_image009

The Visio projects that you create by using this wizard are compatible only with Microsoft Office Visio 2003 or later. They will not work with other versions of Visio.

Projects created by these wizards provide examples of recommended Visio development practices. Once you have used the wizard to create a Visio project, you can explore the project code and settings to learn more about how Visio add-ons and add-ins should work.

Depending on the programming language that you choose with this wizard, you can create different types of projects.

When you use the wizard for the Visual Basic .NET or C# programming languages, you can create projects of the following types:


  • Executable add-ons (EXEs)

  • COM add-ins (DLLs)

When you use the wizard for the C++ programming language, you can create projects of the types listed previously as well as VSL add-ons.

In the next steps we will build an add-on without the wizard and then build one with the wizard and contrast the two projects in Visual Studio.


Try it! Create a project using the Windows Application template.

We will contrast this with using the add-in wizard afterwards.

  1. Create a simple Visio add-on as a Windows Application. This add-on will start Visio, open a stencil and build a simple flowchart. Follow the directions from the article How to Automate Visio with Visual Basic .Net listed in the Additional Resources section of this module.

Note:

This example is a little out of date. Add a reference to the Visio 2010 type library instead of Visio 2002. Second, you will need to add one line of code at the beginning of Module1 to work with the Visio 2010 PIAs. See the next step for details. Third, there are a couple of uninitialized variable warnings that should be fixed.




  1. To make this example work with the Microsoft Office PIAs, add the following line of code at the beginning of Module 1.

Imports Microsoft.Office.Interop




Note:

A finished example of this project is in the Samples folder for this course under the folder WindowApplication1.




  1. Copy the WindowApplication1.exe file to the desktop.

  2. From Visio modify the add-ons file path to include the Desktop. Close Visio.

  3. Restart Visio and run the add-on from the Tools menu.
Try this!

Create an add-on project using the Visio wizard for Visual Studio.

  1. Create another project using the Visio add-in wizard. Choose File > New > Project… This opens the New Project dialog. Give the Project and the Solution a name such as MyAddOn.

  2. Under Project Types choose Visual Basic.

  3. Under Templates choose Visio add-in or add-on. This starts the wizard. Choose Next.

  4. For the add-on type choose Create a Visio EXE add-on. Choose Next.

  5. Choose Finish to close the wizard and create the project. The default project displays the argument string that is passed to the add-on in a dialog box. We won’t change the default code.

  6. In Visual Studio build the project, Build > Build MyAddOn. This creates an .exe file in the project bin folder.

  7. Copy MyAddOn.exe to the desktop and make sure the add-ons paths in Visio is set to search this folder. You may have to restart Visio in order for the add-on to show in the Tools menu.

  8. From Visio run the add-on from the Tools menu: Tools > Add-Ons > MyAddOn. The add-on will display the dialog below.



  1. Add a shape to the drawing and run the macro from the double click event of the shape. You can use the Format > Behavior dialog or enter the formula

=RUNADDON("MyAddOn.exe")


directly in the EventDblClick cell in the ShapeSheet. Double click the shape. The add-on will display a dialog similar to the one below.


Note:

An add-on can be run when a cell formula is evaluated. When this happens, Visio automatically sends a command string to the add-on with the following information:

/visio=instanceHandle /doc=docIndex /page=pageIndex /shape=NameID



This information can be used by the add-on to access the shape that caused the add-on to execute.



Try it! Create a COM Add-in project using the Visio wizard for Visual Studio.

  1. Create another project using the Visio add-in wizard. Choose File > New > Project… This opens the New Project dialog. Give the Project and the Solution a name such as MyAddIn.

  2. Under Project Types choose Visual Basic.

  3. Under Templates choose Visio add-in or add-on. This starts the wizard. Choose Next.

  4. For the add-on type choose Create a Visio COM add-in. Choose Next.

  5. Give the add-in a meaningful name and description. Choose Next.

  6. Select Load the add-in when the Visio application loads. Choose Next.

  7. Choose Finish to close the wizard and create the project. The default project will display a message box when the add-in is loaded.

  8. In Visual Studio build the project, Build > Build Solution. This adds the generated .dll to the Windows registry.

  9. Close Visio and then start Visio. The add-in loads when Visio starts and displays the message “MyAddIn connected”.
Contrast the three projects in Visual Studio

Let’s take a look at these three projects.
Using Windows Application template

The project is a bare bones project when it is created. A default form is created, but that is about it. The developer has to do everything else. In this example we completed the form and then added a module and code that launched Visio and built the drawing.

  • The form is the startup for the application by default, but you can change this in the Project Properties window.

  • There is also no setup project created for us.
Using the Visio template to create an .EXE

A default project is built with code that parses the command string that is sent to the add-on. When creating your own add-on this code can be deleted if it is not needed by the add-on. In addition to this code, the following is created as part of the project.

  • There is a main procedure in VisioEXEAddon.vb that serves as the startup location for the project. Whether a form is displayed is controlled by this code.

  • There is a setup project constructed by default.

  • There is a default application icon file.

  • There is a default assembly created and default project resource strings.
Using the Visio template to create a COM add-in

A default project is built with code that displays a message box when the add-in is first loaded. Also created for this project:

  • A Connect.vb module. This module contains code that implements the interface for connecting to a COM add-in.

  • There is a setup project constructed by default.

  • There is a default assembly created and default project resource strings.





Download 0.78 Mb.

Share with your friends:
1   ...   25   26   27   28   29   30   31   32   ...   36




The database is protected by copyright ©ininet.org 2024
send message

    Main page