DesktopApplication

From Xojo Documentation

Revision as of 21:08, 23 July 2021 by Gperlman (talk | contribs)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Class (inherits from Object)


New in 2021r3

Contains properties, methods, and events for managing desktop applications.

Events
Activated Closing MenuBarSelected
AppearanceChanged Deactivated Opening
AppleEventReceived DocumentCreated UnhandledException
CancelClosing DocumentOpened
Properties
AllowAutoQuit DockItem MinorVersion fa-lock-32.png
AllowHiDPI fa-lock-32.png ExecutableFile fa-lock-32.png MouseCursor
BugVersion fa-lock-32.png LastWindowIndex fa-lock-32.png NonReleaseVersion fa-lock-32.png
BuildDateTime fa-lock-32.png MDIWindow RegionCode fa-lock-32.png
Copyright fa-lock-32.png MajorVersion fa-lock-32.png StageCode fa-lock-32.png
Description fa-lock-32.png MenuBar Version fa-lock-32.png
Methods
AddTrayItem OpenDocument Window
DoEvents RefreshMenuBar WindowCount
HideTooltip RemoveTrayItem Windows
NewDocument ShowTooltip

Class Constants

The following class constants can be used to specify the value of the StageCode property.

Constant Value
Development 0
Alpha 1
Beta 2
Final 3

Notes

fa-info-circle-32.png
For web apps, refer to WebApplication. For console apps, refer to ConsoleApplication. For iOS apps, refer to MobileApplication.

A subclass of DesktopApplication (called App) is automatically added when you create a new Desktop project. This new subclass gives you access to the DesktopApplication class methods and events.

The App subclass has its own menu handlers which can be used to handle menu items when no windows are open or for menu items that should call the same menu handler regardless of which window is frontmost. You can change the global menubar by assigning a different menubar to its MenuBar property.

See the DesktopControl class for information on changing the cursor and adding cursors to your project.

The App function returns a reference to an instance of the subclass of Application in your project. See the App function for more information.

To change the app icon, click the Icon that is displayed in the Inspector when the App object is selected. Refer to UserGuide:App Icons for more information.

Adding Additional DesktopApplication Subclasses

If you wish, you can add additional subclasses based on the DesktopApplication class to the project, but it is not necessary. If you do so, the one that is added to the project automatically is the one referred to by the App function and it is the one that will show the project’s build settings.

Version Information

If AutoIncrementVersionInformation is checked (a design-time property) then the NonReleaseVersion property is increased by one each time you do a build (but not when you run the project).

The compiler truncates version information when building Windows applications when the version information is too long to store into the executable file. The current byte limitations for these fields are as follows:

Field Maximum length (bytes)
Long Version 79
Short Version 39
Package Info 253
Region 21
Release 11

Sample Code

You can get the location of the folder in which the app is running, by getting the Parent of the executable file:

Var f as FolderItem
f = App.ExecutableFile.Parent

The following code in the Pressed event of a DesktopButton causes an OutofBoundsException runtime error when the counter, i, reaches the value of FontCount.

For i As Integer = 1 To FontCount
ListBox1.AddRow(Font(i))
Next

Since there is no exception handler within the method, the runtime exception is passed up to the DesktopApplication class, triggering the UnhandledException event.

This code in the UnhandledException event of the App class "catches" the unhandled OutOfBoundsException. Of course, it catches all unhandled OutOfBoundsExceptions throughout the application, so it doesn't know where the error occurred. You could instead place an Exception statement within the DesktopButton's Pressed event so that you can provide more specific diagnostics.

Function UnhandledException(error As RuntimeException) As Boolean
If error IsA OutOfBoundsException Then
MessageBox("An OutOfBounds Exception error has occurred!")
End If
Return True
End Function

See Also

App, System, objects; AppleEvent, ConsoleApplication, MDIWindow, ServiceApplication, WebApplication, MobileApplication classes.