home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ICLUI.ZIP / HELLO3 / AHELLOW3.CPP next >
Text File  |  1993-03-06  |  9KB  |  137 lines

  1. /******************************************************************************/
  2. /* HELLO WORLD SAMPLE PROGRAM - Version 3: Class Implementation (AHELLOW3.CPP)*/
  3. /*                                                                            */
  4. /* COPYRIGHT: Copyright (C) International Business Machines Corp., 1992,1993. */
  5. /*                                                                            */
  6. /* DISCLAIMER OF WARRANTIES:                                                  */
  7. /*   The following [enclosed] code is sample code created by IBM              */
  8. /*   Corporation.  This sample code is not part of any standard IBM product   */
  9. /*   and is provided to you solely for the purpose of assisting you in the    */
  10. /*   development of your applications.  The code is provided "AS IS",         */
  11. /*   without warranty of any kind.  IBM shall not be liable for any damages   */
  12. /*   arising out of your use of the sample code, even if they have been       */
  13. /*   advised of the possibility of such damages.                              */
  14. /******************************************************************************/
  15. // NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE
  16. //**************************************************************************
  17. // C++ Hello World History and Key Functions:                              *
  18. //   Version 1:                                                            *
  19. //      - Creates and runs a simple application                            *
  20. //      - Creates the main window (IFrameWindow)                           *
  21. //      - Creates a static text control set to "Hello, World!" as the      *
  22. //         client window                                                   *
  23. //                                                                         *
  24. //   Version 2: (lines with v2 in column 79-80)                            *  v2
  25. //      - Create Main Window (AHellowWindow) as subclass of IFrameWindow   *   .
  26. //      - Gets the "Hello, World!!" text string and other items from a     *   .
  27. //         resource file                                                   *   .
  28. //      - Sets the window title from a resource file                       *   .
  29. //      - Creates and sets the information area at the bottom of the       *   .
  30. //         client area                                                     *  v2
  31. //                                                                         *
  32. //   Version 3: (lines with v3 in column 79-80)                            *  v3
  33. //      - Add Alignment (Left, Center, Right) Menu Bar                     *   .
  34. //      - Add Command Processing to set the "Hello, World" alignment       *   .
  35. //      - Place check in front of the Left, Center or Right Menu Item      *   .
  36. //      - Create and maintain Status Line with current alignment status    *  v3
  37. //**************************************************************************
  38.                                         //Include IBM UI class headers:
  39. #include <iapp.hpp>                     //IApplication Class
  40. #include <istattxt.hpp>                 //IStaticText Class
  41. #include <iinfoa.hpp>                   //IInfoArea Class                     v2
  42. #include <imenubar.hpp>                 //IMenuBar Class                      v3
  43. #include <ifont.hpp>                    //IFont                               v3
  44.  
  45. #include "ahellow3.hpp"                 //Include AHelloWindow Class headers  v2
  46. #include "ahellow3.h"                   //Include our Symbolic definitions    v2
  47.  
  48. //*************************************************************************
  49. // main  - Application entry point                                        *
  50. //*************************************************************************
  51. void main()                             //Main Procedure with no parameters
  52. {
  53.   AHelloWindow mainWindow (WND_MAIN);   //Create our main window on the
  54.                                         // desktop
  55.   IApplication::current().run();        //Get the current application and
  56.                                         // run it
  57. } /* end main */
  58.  
  59. //**************************************************************************
  60. // AHelloWindow :: AHelloWindow - Constructor for our main window          *
  61. //**************************************************************************
  62. AHelloWindow :: AHelloWindow(unsigned long windowId)
  63.   : IFrameWindow (                      //Call IFrameWindow constructor       v2
  64.     IFrameWindow::defaultStyle()        //  Use default plus                  v2
  65.     | IFrameWindow::minimizedIcon,      //  Get Minimized Icon from  RC file  v2
  66.     windowId)                           //  Main Window ID
  67. {
  68.   hello=new IStaticText(WND_HELLO,      //Create Static Text Control
  69.     this, this);                        //  Pass in myself as owner & parent
  70.   hello->setText(STR_HELLO);            //Set text in Static Text Control     v2
  71.   hello->setAlignment(                  //Set Alignment to Center in both
  72.     IStaticText::centerCenter);         //  directions
  73.   setClient(hello);                     //Set hello control as Client Window
  74.  
  75.   infoArea=new IInfoArea(this);         //Create the information area         v2
  76.   infoArea->setInactiveText(STR_INFO);  //Set information area text from RC   v2
  77.  
  78.   statusLine=new IStaticText            //Create Status Area using Static Textv3
  79.     (WND_STATUS, this, this);           //  Window ID, Parent, Owner Parameters.
  80.   statusLine->setText(STR_CENTER);      //Set Status Text to "Center" from Res .
  81.   addExtension(statusLine,              //Add Status Line above the client     .
  82.     IFrameWindow::aboveClient,          //  and specify the height             .
  83.     IFont(statusLine).maxCharHeight()); //  and specify height                v3
  84.  
  85.   handleEventsFor(this);                //Set self as event handler (commands)v3
  86.   menuBar=new IMenuBar(WND_MAIN, this); //Create Menu Bar for main window      .
  87.   menuBar->checkItem(MI_CENTER);        //Place Check on Center Menu Item     v3
  88.  
  89.   sizeTo(ISize(400,300));               //Set the size of main window         v2
  90.   setFocus();                           //Set focus to main window
  91.   show();                               //Set to show main window
  92.  
  93. } /* end AHelloWindow :: AHelloWindow(...) */
  94.  
  95. //**************************************************************************  v3
  96. // AHelloWindow :: command                                                 *   .
  97. //   Handle menu commands                                                  *   .
  98. //**************************************************************************   .
  99. Boolean AHelloWindow :: command(ICommandEvent & cmdEvent)                   // .
  100. {                                                                           //v3
  101.   switch (cmdEvent.commandId()) {       //Get command id                      v3
  102.  
  103.     case MI_CENTER:                     //Code to Process Center Command Item v3
  104.       hello->setAlignment(              //Set alignment of hello text to       .
  105.         IStaticText::centerCenter);     //  center-vertical, center-horizontal .
  106.       statusLine->setText(STR_CENTER);  //Set Status Text to "Center" from Res .
  107.       menuBar->checkItem(MI_CENTER);    //Place Check on Center Menu Item      .
  108.       menuBar->uncheckItem(MI_LEFT);    //Uncheck Left Menu Item               .
  109.       menuBar->uncheckItem(MI_RIGHT);   //Uncheck Right Menu Item              .
  110.       return(true);                     //Return command processed             .
  111.       break;                            //                                    v3
  112.  
  113.     case MI_LEFT:                       //Code to Process Left Command Item   v3
  114.       hello->setAlignment(              //Set alignment of hello text to       .
  115.         IStaticText::centerLeft);       //  center-vertical, left-horizontal   .
  116.       statusLine->setText(STR_LEFT);    //Set Status Text to "Left" from Res   .
  117.       menuBar->uncheckItem(MI_CENTER);  //Uncheck Center Menu Item             .
  118.       menuBar->checkItem(MI_LEFT);      //Place Check on Left Menu Item        .
  119.       menuBar->uncheckItem(MI_RIGHT);   //Uncheck Right Menu Item              .
  120.       return(true);                     //Return command processed             .
  121.       break;                            //                                    v3
  122.  
  123.     case MI_RIGHT:                      //Code to Process Right Command Item  v3
  124.       hello->setAlignment(              //Set alignment of hello text to       .
  125.         IStaticText::centerRight);      //  center-vertical, right-horizontal  .
  126.       statusLine->setText(STR_RIGHT);   //Set Status Text to "Right" from Res  .
  127.       menuBar->uncheckItem(MI_CENTER);  //Uncheck Center Menu Item             .
  128.       menuBar->uncheckItem(MI_LEFT);    //Uncheck Left Menu Item               .
  129.       menuBar->checkItem(MI_RIGHT);     //Place Check on Right Menu Item       .
  130.       return(true);                     //Return command processed             .
  131.       break;                            //                                    v3
  132.  
  133.   } /* end switch */                    //                                    v3
  134.  
  135.   return(false);                        //Return command not processed        v3
  136. } /* end HelloWindow :: command(...) */                                     //v3
  137.