| Managing the User Interface and Controlling the Application |
As the overview diagram shows, the root object of the IQL object model is McApplication. This object exposes most other IQL objects through its properties and methods but also allows you to control the application's User Interface to do such things as displaying information in various ways, displaying Dialogs, changing menus and toolbars, loading and saving settings, responding to Application events, or managing collections of objects like Identities and Projects.
The ObjectModelIntro.iqp VBA project can be loaded in IQstudio to test some of the following examples as well as others.
The Application can be used to display diagnostic information such as in the following example:
' Name is the default property
MsgBox Application
' Simple output and formating
Debug.Print Name & " is installed in " & Path
Or use the Output window and the status bar for more advanced output:
' First make sure the output window is visible, select "Output" page
Output.Show "Output"
' Clear the default page and make the font bigger and bold
Output.Clear
Output.Font.Bold = True
Output.Font.Size = 20
' Print the image size in the output window (which is the default page)
Output.PrintMessage ActiveImage.DisplayName & " is " & ActiveImage.Width & "x" & ActiveImage.Height
' Also display the name in the first status pane
StatusBar.Panes(0).Caption = ActiveImage.DisplayName
Simple Application properties like Visible or FullScreen are used to control the visibility of the Application window:
' This is important when the application is started by automation
Application.Visible = True
' Switch to full screen mode
FullScreen = True
' Wait for user input
While MsgBox("Are we done?", vbYesNo) <> vbYes
Wend
' End full screen mode
FullScreen = False
The VBA window is also accessible to user macros:
' Use the VBE object model to display the VBA IDE
VBE.MainWindow.Visible = True
The Dialogs collection allows to control all the tool dialogs and their pages. User defined dialogs can also be created as explained in the Creating Dialogs section.
' Use the dialog collection to show the contrast dialog
Application.Dialogs("Contrast").Show
Menus and toolbars are exposed in the object model through the McCommandBars collection. This set of objects gives access to menu entries and toolbar buttons like in the following 2 examples.
' Use the CommandBars collection to hide the annotations toolbar
Application.CommandBars("Annotation").Visible = False
' Use the CommandBars collection to disable the Save command
Application.CommandBars("MenuBar").Controls("File").Controls("Save").Enabled = False
The McSettings object exposed as Settings in the Application allows to associate persistent information with the current identity. Most tools use this capability to adapt their dialogs to user preferences.
' Settings can store any variable type: store an array
Settings.Set "MySetting", Array(1, 2, 3, 4)
' Use McToText to display the values
MsgBox McToText( Settings.Get("MySetting") )
The Application behavior can be controlled by monitoring its events like in the following piece of VBA code which could be pasted into the ThisSession module in the VBA editor.
' Respond to Shutdown event by prompting the user to confirm
Private Sub McApplication_BeforeShutdown(Cancel As Boolean)
' Ask the user to confirm
If MsgBox("Are you sure?", vbYesNo) <> vbYes Then
Cancel = True
End If
End Sub