Menu

Basic_OWL_Application

OWL includes many classes to write your applications more quickly and easily. In a full-size application you need to use many of OWL's classes, while in a basic OWL application you need only draw on OWL's TApplication and TFrameWindow classes. The TApplication class encapsulates the data and functions that make up an application, whereas the TFrameWindow class encapsulates the data and functions that make up an application's main window.

Your main window class will usually derive from OWL's TFrameWindow. If you want to use a control bar and a status bar, you will derive your class from TDecoratedFrame. In your class you must provide at least a constructor. You'll also always want to provide a response table, which enables your window to respond to Windows messages, and you'll often need to override the virtual functions SetupWindow and CleanupWindow:

<pre>
// Usually in a *.h file:

#include <owl/framewin.h>

class TMyFrame : public owl::TFrameWindow
{
  public:
    TMyFrame(owl::TWindow* parent, LPCTSTR title);
    virtual ~TMyFrame();

  protected:
    virtual void SetupWindow(); // TWindow override
    virtual void CleanupWindow(); // TWindow override

  DECLARE_RESPONSE_TABLE(TMyFrame);
};

</pre>

The response table is defined separately:

&lt;pre&gt;
// Usually in a *.cpp file:

using namespace owl;

DEFINE_RESPONSE_TABLE1(TMyFrame, TFrameWindow)
  // ...insert response table entries here...
END_RESPONSE_TABLE;

</pre>

In your main window's constructor you can perform initialization that do not require a valid window handle, i.e. before the window element is created on-screen:

&lt;pre&gt;
// Usually in a *.cpp file:

using namespace owl;

TMyFrame::TMyFrame(TWindow* parent, LPCTSTR title)
: TFrameWindow(parent, title) // Always call the base class constructor.
{
  // ...other initialization here...
}

TMyFrame::~TMyFrame()
{
  // ...cleanup here...
}

</pre>

The SetupWindow and CleanupWindow functions provide initialization and cleanup services for the window class. You will use them to do initialization and cleanup that requires that the window object has a valid window handle, i.e. while the window element exists on-screen:

&lt;pre&gt;
// Usually in a *.cpp file:

using namespace owl;

void TMyFrame::SetupWindow()
{
  TFrameWindow::SetupWindow(); // Always call the base class function.

  // ...insert your initialization code here...
}

void TMyFrame::CleanupWindow()
{
  // ...insert your cleanup code here....

  TFrameWindow::CleanupWindow(); // Always call the base class function.
}

</pre>

The next step is to write your application class, which should be derived from OWL's TApplication class:

&lt;pre&gt;
// Usually in a *.h file:

#include &lt;owl/applicat.h&gt;

class TMyApplication : public owl::TApplication
{
  public:
    TMyApplication();

  protected:
    virtual void InitMainWindow(); // TApplication override
};

</pre>

In the constructor, give the application a name. In the body of the InitMainWindow function, construct your main window and call SetMainWindow passing a pointer to your main window object:

&lt;pre&gt;
// Usually in a *.cpp file:

using namespace owl;

TMyApplication::TMyApplication()
: TApplication(_T("Basic OWL Application")) 
{
  // ...other initialization here...
}

void TMyApplication::InitMainWindow()
{
  TMyFrame* frame = new TMyFrame(0, GetName()); // Use the application name as title.
  SetMainWindow(frame);
}

</pre>

And finally, an OWL application begins execution at the OwlMain function, which you must provide:

&lt;pre&gt;
// Usually in a *.cpp file:

int OwlMain(int argc, _TCHAR* argv[])
{
  return TMyApplication().Run();
}

</pre>

Notes

This article has been updated for OWLNext 6.32. If you come from an earlier version, then note that OWLNext is now much stricter about namespaces. Also note that the OWLNext namespace name has changed from "OWL" to "owl", although the former is still supported as a macro in OWL5_COMPAT mode.


Related

Wiki: Knowledge_Base