home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / samples / sample5 / sample5.cpp < prev    next >
Text File  |  1997-04-07  |  3KB  |  124 lines

  1. #include "sample5.h"
  2.  
  3. #include XColor_i
  4. #include XMessageBox_i
  5. #include XString_i
  6. #include XMenuBar_i
  7. #include XControlEvent_i
  8. #include XPoint_i
  9. #include XException_i
  10.  
  11.  
  12. #define DEPARTMENT 1
  13. #define WORKER 2
  14.  
  15. #include <stdlib.h>
  16.  
  17. MyApp * app;
  18. XResourceLibrary * resourceLib;
  19.  
  20. //here a window is created out of the resource-file, the last parameter tells the library
  21. //to build the window with the ID given in XResource. Works with resource-DLLs too.
  22. MyAppWindow :: MyAppWindow( XApplication * app, XResource * r ): XScrollWindow( r, "Sample5 - Container", XFrameWindow::defaultStyle | FRM_TASKLIST | FRM_CENTER,  NULL, NULL, TRUE )
  23. {
  24.    //we add a menubar to the window, the resources are in the resource-DLL
  25.    XResource res(IDM_MENU, resourceLib);
  26.    XMenuBar * menu = new XMenuBar( this, &res);
  27.  
  28.    //add scroller to the window
  29.    AddVertScroller();
  30.    AddHorzScroller();
  31.  
  32.    //Activate the window
  33.    Activate();
  34. }
  35.  
  36.  
  37. MyAppWindow :: ~MyAppWindow()
  38. {
  39. }
  40.  
  41.  
  42. /* here the commands of the menu and the pushbuttons are posted */
  43. BOOL MyAppWindow :: DoCommand( LONG com)
  44. {
  45.    switch( com )
  46.       {
  47.          //the two menu-items of interest, we terminate the application in every case
  48.          case IDM_CANCEL:
  49.          case IDM_OK:
  50.          //also push-buttons post a command if they are pressed
  51.          case PUSH_OK:
  52.          case PUSH_CANCEL:
  53.             {
  54.                app->Terminate();
  55.             }
  56.             break;
  57.       }
  58.    return TRUE;
  59. }
  60.  
  61.  
  62. //here the control-events of our window-contents are posted
  63. void MyAppWindow :: DoControl( XControlEvent * event)
  64. {
  65.    switch( event->GetEventID()) //what type of event?
  66.       {
  67.          case WIN_CHANGED:      //window-content changed
  68.             {
  69.                switch( event->GetWindowID()) //which window posted the event?
  70.                   {
  71.                      case RADIO_MALE:        //the radio-button MALE is clicked
  72.                         //add your code here to handle the event
  73.                         break;
  74.                      case RADIO_FEMALE:      //the radio-button FEMALE is clicked
  75.                         //add your code here to handle the event
  76.                         break;
  77.                      default:
  78.                         break;        //entry-field, ignored in this sample
  79.                   }
  80.             }
  81.       }
  82. }
  83.  
  84.  
  85. MyApp :: MyApp(): XApplication()
  86. {
  87.    //we create a resource-DLL (sample5.dll), it contains the resources for the window
  88.    resourceLib = new XResourceLibrary( this, "c:\\os2\\apps\\dll\\sample5.dll" );
  89.  
  90.    //we create a resource with our DLL which contains the id of the resource-window (see sample5.dlg)
  91.    XResource r( WIN_MAIN, resourceLib);
  92.    app = this;
  93.  
  94.    //create the window
  95.    window = new MyAppWindow( this, &r );
  96.  
  97.    //because we have added a menubar and scrollers, we must resize the window
  98.    //but we cannot do it in the construcor!
  99.    XRect rec;
  100.  
  101.    window->GetSize( &rec );
  102.  
  103.    rec.SetHeight( rec.GetHeight() + 40);
  104.    rec.SetWidth( rec.GetWidth() + 15);
  105.  
  106.    window->SetSize( &rec );
  107. }
  108.  
  109.  
  110. void main ( void)
  111. {
  112.    try
  113.    {
  114.       MyApp * app = new MyApp();  //create a new application
  115.    }
  116.    catch( XException e)
  117.    {
  118.       XMessageBox( e.GetErrorMessage());
  119.       exit(-1);
  120.    }
  121.  
  122.    app->Start();               //let the application work
  123. }
  124.