In all ViewKit ObjectPak applications you must create a single instance of the VkApp class (or a derived class) before instantiating any other ObjectPak objects. The VkApp constructor initializes the Xt Intrinsics and creates an invisible shell to serve as the parent for all the application's main windows. ViewKit ObjectPak supports the commonly-used multi-shell architecture described in X Window System Toolkit (Asente and Swick, 1990). ObjectPak creates all windows (using the VkSimpleWindow and VkWindow classes described in Chapter 4--ViewKit Windows) as popup children of the shell created by VkApp.
When you create an instance of the VkApp class, the constructor assigns a pointer to the VkApp object to the global variable theApplication. The <Vk/VkApp.h> header file declares this global variable as follows:
- extern VkApp *theApplication;
As a result, the theApplication pointer is available in any file that includes the <Vk/VkApp.h> header file. This provides easy use of VkApp's facilities and data throughout your program.
Syntax
The syntax of the VkApp constructor is:
Arguments
The appClassName argument designates the application class name, which is used when loading application resources. Note that VkApp differs from other ViewKit ObjectPak components in that you provide the application class name as an argument to the constructor rather than overriding the className() function. This allows you to set the application class name without creating a subclass of VkApp.VkApp also differs from other ViewKit ObjectPak components in that you do not provide a component name in the constructor; instead, ViewKit ObjectPak uses the command that you used to invoke your application (argv[0]) as the component name.
The second and third arguments to the VkApp constructor must be pointers to argc and the application's argv array. The VkApp constructor passes these arguments to XtOpenDisplay(3), which parses the command line according to the standard Xt command-line options, loads recognized options into the application's resource database, and modifies argc and argv to remove all recognized options.
You can specify additional command-line options to parse by passing an XrmOptionDescRec(3) table as the options argument and specifying the number of entries in the table with the numOptions argument. This is sufficient for setting simple resource values from the command line.
Setting variables using the command line or resource values
However, to set application-level variables using either the command line or resource values, you must perform the following tasks:
- Derive a subclass of VkApp.
- Use the protected member function VkApp::parseCommandLine() to parse command-line options.
- Use getResources() to set the variables based on resource values.
Example 16. in "Deriving Classes from VkApp" illustrates this process.