OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Calling initialization functions

TApplication contains three initialization functions:

Function Description

  • TApplication::InitApplication() Initializes the first instance of the application.
  • TApplication::InitInstance() Initializes each instance of the application.
  • TApplication::InitMainWindow() Initializes the application's main window.

Initializing the Application

How these functions are called depends on whether or not this is the first instance of the application. For 16-bit applications, InitApplication is called only for the first instance of the application on the system. InitInstance is the next function called for the first instance, and it is the first function called by additional instances. InitInstance calls InitMainWindow.

In the case of 32-bit applications, each application runs in its own address space, with no shared instance data, making each instance a first instance. Every time you start a 32-bit application, it performs both first-instance initialization and each-instance initialization.

If the current instance is a first instance (indicated by the data member hPrevInstance being set to zero), InitApplication is called. You can override InitApplication in your derived application class; the default InitApplication has no functionality.

For example, you could use first-instance initialization to make the main window's caption indicate whether it's the first instance. To do this, add a data member called WindowTitle in your derived application class. In the constructor, set WindowTitle to "Additional Instance". Then override InitApplication to set WindowTitle to "First Instance". If your application is the first instance of the application, InitApplication is called and overwrites what the constructor set WindowTitle to. The following example shows how the code might look:

#include <owl\applicat.h>
#include <owl\framewin.h>
#include <cstring.h>
class TTestApp : public TApplication
{
public:
TApplication("Instance Tester"),
WindowTitle("Additional Instance") {}
protected:
string WindowTitle;
void InitApplication() {
WindowTitle = string("First Instance"); }
void InitMainWindow() {
SetMainWindow(
new TFrameWindow(0, WindowTitle.c_str())); }
};
int
OwlMain(int /* argc */, char* /* argv */[])
{
return TTestApp().Run();
}
Definition of class TApplication.
Definition of class TFrameWindow.
STDAPI_(owl::TDocTemplate **) GetDocTemplateHead(owl STDAPI_(owl::TModule **) GetModulePtr(owl in OwlMain)(int argc, TCHAR *argv[])
Main entry point for an Owl application.
Definition module.h:391

When multiple 16-bit instances of this application are open on the desktop, the first one has the title "First Instance" and each subsequent instance has the title "Additional Instance".

Because each instance of a 32-bit application is perceived as the first instance of the application, multiple 32-bit copies running at the same time all have the caption "First Instance".

See Also