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

  1. // Kroni's Classes: Demonstration: Input dialog with special classes
  2. // (c) 1997 Wolfgang Kronberg
  3. // file: dialog2.cpp
  4.  
  5. // ************************************************************************* //
  6. // *                 Demonstration of Kroni's Classes                      * //
  7. // *                                                                       * //
  8. // *                 Input Dialog with special classes                     * //
  9. // *                                                                       * //
  10. // *  Demonstrated classes:                                                * //
  11. // *    KrAsyncMain                                                        * //
  12. // *    KrCommonTextOutput                                                 * //
  13. // *    KrWinComm                                                          * //
  14. // *    KrBitfield                                                         * //
  15. // *    KrChoice                                                           * //
  16. // ************************************************************************* //
  17.  
  18.  
  19. #include "krcto.hpp"                             // Support to re-route cout to a window
  20. #include "krasyncm.hpp"                          // Support for asynchronous main function
  21. #include "krwc.hpp"                              // Support for dialog input (windowed communication)
  22.  
  23. #include <iframe.hpp>                            // IFrameWindow
  24.  
  25.  
  26. // First of all, all global window objects should be declared static and before all functions.
  27. //   This is the comon UICL way to define a frame window and its childs:
  28.  
  29. static IFrameWindow mainWindow ("Demonstration of Kroni's Classes: Special Dialog Classes", 0x1000);
  30.                                                  // Our main window
  31. static KrCommonTextOutput text (IC_FRAME_CLIENT_ID, &mainWindow, &mainWindow);
  32.                                                  // This window will hold all text output
  33.  
  34. // The object which take user input does not need to be defined here, but it's easier that way.
  35.  
  36. static KrWinComm wcin;
  37.  
  38.  
  39. // We must always derive a class from the virtual class KrAsyncMain in a standard way:
  40.  
  41. class MyMain : public KrAsyncMain
  42. {
  43. public:
  44.   MyMain (IWindow * mainWindow) : KrAsyncMain (mainWindow) {};
  45.                                                  // We must forward the original object's only constructor
  46.   virtual void main (IEvent & event);            // This will be our actual new main function
  47. };
  48.  
  49.  
  50. // Next define the asynchronous main function. Doing calculations here does not block message processing.
  51.  
  52. void MyMain::main (IEvent & event)               // Do in this effective main function whatever you want!
  53. {
  54.  
  55.   switch (event.parameter1())                    // Use this to define the different parts of your program
  56.      {
  57.      case cmdStartUp:                            // This part will be run when the program first comes up.
  58.  
  59.         cout = text.stream();                    // Assign the KrTextOutput object's stream to cout
  60.         cout.setf (ios::unitbuf);                // Unfortunately, the above line does not copy this property
  61.  
  62.         static KrBitfield bf;                    // Let the user click several options on/off independently
  63.         int bf1 = bf.add ("Space");              // The int variables are used to identify the item later.
  64.         int bf2 = bf.add ("Lots of Money");      // You may also define them a priori, but this is easier.
  65.                                                  // All options are off by default, but his can be changed.
  66.  
  67.         static KrChoice ch;                      // Let the user choose exactly one of several choices.
  68.         int ch1 = ch.add ("Betazoid");
  69.         int ch2 = ch.add ("Klingon");
  70.         ch.set (ch1);                            // One choice should be set as the default.
  71.  
  72.         wcin << "'Enterprise' has something to do with..." >> bf;
  73.         wcin << "Deanna Troi is..." >> ch
  74.              >> display;                         // The display manipulator will work with both
  75.                                                  //   the >> and the << operator.
  76.  
  77.         cout << "Your choices:\n";
  78.         cout << " 'Enterprise' has " << (bf.isChecked(bf1)?"something":"nothing") << " to do with Space\n";
  79.         cout << " 'Enterprise' has " << (bf.isChecked(bf2)?"something":"nothing")
  80.              << " to do with Lots of Money\n";
  81.         cout << " Deanna Troi is " << (ch.get()==ch1?"Betazoid":"Klingon") << "\n";
  82.  
  83.         break;                                   // Our effective main program ends here.
  84.      };
  85. };
  86.  
  87.  
  88. int main (int argc, char **argv, char **envv)    // This should include all initial window definitions;
  89. {                                                //   the other stuff should be in MyMain::main().
  90.   IApplication::current().setArgs(argc,argv);    // This is "good style" when using the UICL.
  91.                                                  //   Do always include this line.
  92.  
  93.   // First, we must make sure that our window is shown on the screen.
  94.   //   This is ordinary UICL code.
  95.  
  96.   mainWindow.setClient (&text);
  97.   mainWindow.sizeTo (ISize(500,300));
  98.   mainWindow.setFocus ();
  99.   mainWindow.show ();
  100.  
  101.   // These should always be the very last statements in the main() function:
  102.  
  103.   MyMain myMain (&mainWindow);                   // initializes the use of the function MyMain::main
  104.   IApplication::current().run();
  105.   return 0;
  106. };
  107.  
  108.