home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / krcls012.zip / KrClass / demo / hello.cpp < prev    next >
Text File  |  1997-02-24  |  5KB  |  88 lines

  1. // Kroni's Classes: Demonstration: "Hello World" program
  2. // (c) 1997 Wolfgang Kronberg
  3. // file: hello.cpp
  4.  
  5. // ************************************************************************* //
  6. // *                 Demonstration of Kroni's Classes                      * //
  7. // *                                                                       * //
  8. // *                          "Hello, World"                               * //
  9. // *                                                                       * //
  10. // *  Demonstrated classes:                                                * //
  11. // *    KrAsyncMain                                                        * //
  12. // *    KrCommonTextOutput                                                 * //
  13. // ************************************************************************* //
  14.  
  15.  
  16. #include "krcto.hpp"                             // Support to re-route cout to a window
  17. #include "krasyncm.hpp"                          // Support for asynchronous main function
  18.  
  19. #include <iframe.hpp>                            // IFrameWindow
  20.  
  21.  
  22. // First of all, all global window objects should be declared static and before all functions.
  23. //   This is the comon UICL way to define a frame window and its childs:
  24.  
  25. static IFrameWindow mainWindow ("Demonstration of Kroni's Classes: Hello, World", 0x1000);
  26.                                                  // Our main window
  27. static KrCommonTextOutput text (IC_FRAME_CLIENT_ID, &mainWindow, &mainWindow);
  28.                                                  // This window will hold all text output, e.g. for use
  29.                                                  //   with common cout.
  30.  
  31. // We must always derive a class from the virtual class KrAsyncMain in a standard way:
  32.  
  33. class MyMain : public KrAsyncMain
  34. {
  35. public:
  36.   MyMain (IWindow * mainWindow) : KrAsyncMain (mainWindow) {};
  37.                                                  // We must forward the original object's only constructor
  38.   virtual void main (IEvent & event);            // This will be our actual new main function
  39. };
  40.  
  41.  
  42. // Next define the asynchronous main function. Doing calculations here does not block message processing.
  43.  
  44. void MyMain::main (IEvent & event)               // Do in this effective main function whatever you want!
  45. {                                                //   However, please note that this function - unlike the
  46.                                                  //   usual main() - will be left before the program exits.
  47.                                                  //   Make sure to define all variables as static or use
  48.                                                  //   new / delete for objects which must survive the exit
  49.                                                  //   of the function.
  50.  
  51.   switch (event.parameter1())                    // Use this to define the different parts of your program
  52.      {
  53.      case cmdStartUp:                            // This part will be run when the program first comes up.
  54.                                                  //   You may define more commands (e.g. as menu entries or
  55.                                                  //   as subprocedures to be called from here) and add them
  56.                                                  //   to this switch instruction.
  57.  
  58.         cout = text.stream();                    // Assign the KrTextOutput object's stream to cout
  59.         cout.setf (ios::unitbuf);                // Unfortunately, the above line does not copy this property
  60.  
  61.         cout << "Hello, World!";
  62.  
  63.         break;                                   // Our effective main program ends here.
  64.      };
  65. };
  66.  
  67.  
  68. int main (int argc, char **argv, char **envv)    // This should include all initial window definitions;
  69. {                                                //   the other stuff should be in MyMain::main().
  70.   IApplication::current().setArgs(argc,argv);    // This is "good style" when using the UICL.
  71.                                                  //   Do always include this line.
  72.  
  73.   // First, we must make sure that our window is shown on the screen.
  74.   //   This is ordinary UICL code.
  75.  
  76.   mainWindow.setClient (&text);
  77.   mainWindow.sizeTo (ISize(500,300));
  78.   mainWindow.setFocus ();
  79.   mainWindow.show ();
  80.  
  81.   // These should always be the very last statements in the main() function:
  82.  
  83.   MyMain myMain (&mainWindow);                   // initializes the use of the function MyMain::main
  84.   IApplication::current().run();
  85.   return 0;
  86. };
  87.  
  88.