Using Custom User Interface Files

3 4

A Microsoft Visio user interface file (VSU) is a means of saving a custom user interface between Visio instances. If your solution makes extensive changes to the Visio user interface, and it's unlikely that your users will run other solutions that also make user interface changes, a VSU file might be a more efficient way of providing a custom user interface.

About Custom.vsu

Beginning with Microsoft Visio 2000, Visio uses a VSU file to preserve user customizations. The first time a user customizes the Visio user interface using the Customize command (on the View menu, click Toolbars), the Visio instance takes a snapshot of the user interface currently in effect (including customizationssupplied by Visio solutions) and, when the user exits the Visio instance, stores it in a file called Custom . vsuin the user's profile folder.

If your solution employs a VSU file to supply a custom user interface, keep the following in mind:

  • If a Custom . vsu file exists on a user's system, the Application object's CustomMenus and CustomToolbars properties return a UIObject object instead of returning Nothing. (In earlier Visio versions, CustomMenus and CustomToolbars returned a UIObject object only if the Visio user interface had been customized by a program that had used a VSU file.)
  • A user's Custom . vsu file is a snapshot of whatever user interface is in effect when the user customized the user interface. If a solution customizes the Visio user interface, and the user then creates a custom toolbar, that user's Custom . vsu represents the solution's user interface plus the user's changes. If a solution then reloads its original VSU file, the Visio instance will appear to "lose" the user's customizations.
  • If the Custom.vsu file is deleted, the Visio instance reverts to the built-in user interface, and recreates the file the next time the user customizes the user interface.

Saving a Custom User Interface File

If you've made extensive user interface changes and intend to save your custom user interface to a VSU file, use the SaveToFile method of the UIObject object. For example:

 uiObj.SaveToFile("c:\solutions\mytools.vsu") 

Loading a Custom User Interface File

You can load a custom user interface file by setting the custom user interface for the Application object. You can also load a custom user interface file (VSU) when an event occurs, such as opening a document.

To load a custom user interface file for an Application object, set the following properties of the object to the name of the custom user interface file:

  • CustomMenusFile Set this property for custom menus and accelerators.
  • CustomToolbarsFile Set this property for custom toolbars and status bars.

For example, to load a custom user interface file each time the users starts Visio, use this statement:

 Visio.Application.CustomToolbarsFile = "c:\solutions\mytools.vsu" 

You need to set these properties for the Application object only once. These properties set the value of the CustomMenusFile and CustomToolbarsFile entries in the Microsoft Windows registry and tell Visio the location of the corresponding custom interface file. If a path is not specified, Visio looks in the folders along the Visio Add-ons path, specified on the File Paths tab (on the Tools menu, click Options). If the specified file cannot be located, or if the registry key is deleted or modified, Visio reverts to the built-in Visio user interface.

To load a custom user interface file when an event occurs, such as opening a document, put the code in the appropriate event for the Document object.

To load a custom user interface file each time a document is opened, use this statement in the DocumentOpened event procedure for the Document object:

 ThisDocument.CustomMenusFile =  "c:\solutions\mytools.vsu" 

If you are programming in an external development environment such as Microsoft Visual Basic, you can load a custom user interface file, make changes to it, and then save the changes to the file.

To load a custom user interface file, use the LoadFromFile method. For example:

 UiObj.LoadFromFile "shortcut.vsu" ...'Make UI changes uiObj.SaveToFile "c:\solutions\mytools.vsu" 

Restoring the Built-in Visio User Interface

If your solution customizes the Visio user interface, it's a good idea to restore the original user interface when your solution finishes running. If your solution detected custom menus or custom toolbars on the user's system, or if the user might have customized the user interface while your solution was running, it should reverse its user interface changes by removing the items it added and restoring those it removed.

If you can be certain that no other customizations should be preserved, you can clear custom menus and custom toolbars to quickly restore the built-in Visio user interface. Clearing custom menus and toolbars does not erase a user's Custom.vsu file, but it does cause Visio to stop using it.

To restore the built-in Visio menus and accelerators, use the ClearCustomMenus method of the Document (or Application) object. To restore the built-in Visio toolbars, use the ClearCustomToolbars method of the Document (or Application) object. For example, to clear the custom menus for a Document object, use this statement:

 ThisDocument.ClearCustomMenus 

For example, to clear custom toolbars for the Application object, use this statement:

 Visio.Application.ClearCustomToolbars 

The next time the document is opened or a Visio instance is run, it uses the built-in Visio user interface.



Developing Microsoft Visio Solutions 2001
Developing Microsoft Visio Solutions (Pro-Documentation)
ISBN: 0735613532
EAN: 2147483647
Year: 2004
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net