[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.4.5 Quick Tutorial

In the following discussion I will try to explain how to build simple applications using the Crystal Space Windowing System. I hope you will understand enough to start writing your own applications; I also hope you will get a deeper knowledge of CSWS during your development (or lab) sessions. In fact, I highly recommend perusing the CSWS header files (or alternatively at the HTML documentation generated from the header files) as they contain a lot of useful information which is not present here.

A Simple Application

The simplest possible application should do the following:

Let's try:

 
#include "csws/csws.h"

int main(int argc, char const* const argv[])
{
  iObjectRegistry* object_reg =
    csInitializer::CreateEnvironment (argc, argv);
  if (!object_reg) return -1;

  if (!csInitializer::SetupConfigManager (object_reg,
    "/config/cswstest.cfg")) return -1;

  if (!csInitializer::RequestPlugins (object_reg, CS_REQUEST_END))
    return -1;

  csApp* app = new csApp(object_reg);
  if (app.Initialize())
    csDefaultRunLoop(object_reg);

  delete app;
  csInitializer::DestroyApplication (object_reg);
}

Pretty simple, eh? So the result is simple as well. We got a gray background, a mouse and nothing more. What the program does is:

If you observe, the above program allocates the `csApp' object on the heap, rather than on the stack as an automatic variable. This is done so that we can manually destroy that object before DestroyApplication() is called. This is important, because no Crystal Space or CSWS functionality should be invoked after DestroyApplication() has been called. By destroying csApp first, we ensure that code in its destructor is invoked early enough.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated using texi2html