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

  1. #include "sample14.h"
  2. #include "dialog.h"
  3.  
  4. #include XMessageBox_i
  5. #include XMenuBar_i
  6. #include XPoint_i
  7. #include XException_i
  8. #include XModelessDialog_i
  9. #include XModalDialog_i
  10.  
  11. #include <stdlib.h>
  12.  
  13. MyApp * app;
  14.  
  15.  
  16. class MyModelessDialog: public XModelessDialog
  17. {
  18.     public:
  19.         MyModelessDialog( XResource * r, XWindow * w):XModelessDialog( r, w)
  20.                 { GetWindow(PUSH_OK)->SetText("OK");}    //init the dialog
  21.         BOOL DoCommand( LONG com );
  22. };
  23.  
  24.  
  25. BOOL MyModelessDialog :: DoCommand( LONG com )
  26. {
  27.    delete this; //a command was posted, destroy the dialog in every case
  28.     return TRUE;
  29. }
  30.  
  31.  
  32. class MyModalDialog: public XModalDialog
  33. {
  34.     public:
  35.         MyModalDialog( XResource * r, XWindow * w):XModalDialog( r, w) 
  36.                 { GetWindow(PUSH_OK)->SetText("OK");} //init the dialog
  37.         BOOL QueryForClose( SHORT com );
  38. };
  39.  
  40.  
  41. BOOL MyModalDialog :: QueryForClose( SHORT com )
  42. {
  43.     return TRUE; //a command was posted, return TRUE to destroy the dialog in every case in this sample
  44. }
  45.  
  46.  
  47. MyAppWindow :: MyAppWindow( XApplication * app, XResource * r ): XScrollWindow( r, "Sample14 - Dialogs", XFrameWindow::defaultStyle | FRM_TASKLIST | FRM_CENTER | FRM_MENU)
  48. {
  49.    Activate();
  50. }
  51.  
  52.  
  53. MyAppWindow :: ~MyAppWindow()
  54. {
  55. }
  56.  
  57.  
  58. /* here the commands of the menu are posted */
  59. BOOL MyAppWindow :: DoCommand( LONG com)
  60. {
  61.    switch( com )
  62.       {
  63.          case IDM_MODELESS:    //show the modeless dialog
  64.             {
  65.                try
  66.                {
  67.                    XResource res( IDM_MODELESSDIALOG, app->GetResourceLibrary());
  68.                         MyModelessDialog * dlg = new MyModelessDialog( &res, this);
  69.                     }            
  70.                     catch( XException e)
  71.                     {
  72.                         XMessageBox( e.GetErrorMessage()); 
  73.                     }
  74.                 }
  75.                 break;
  76.          case IDM_MODAL:        //show the modeless dialog
  77.             {
  78.                try
  79.                {
  80.                         XResource res( IDM_MODALDIALOG, app->GetResourceLibrary());
  81.                         MyModalDialog * dlg = new MyModalDialog( &res, this);
  82.                         dlg->Start();    //dont forgett to make it modal
  83.                     }            
  84.                     catch( XException& e)
  85.                     {
  86.                         XMessageBox( e.GetErrorMessage()); 
  87.                     }
  88.                 }
  89.                 break;
  90.          default:                    //destroy the application
  91.             {
  92.                app->Terminate();
  93.             }
  94.             break;
  95.       }
  96.    return TRUE;
  97. }
  98.  
  99.  
  100. MyApp :: MyApp(): XApplication()
  101. {
  102.    //we create a resource with our DLL which contains the id of the resource-window (see sample5.dlg)
  103.    XResource r( IDM_MENU, GetResourceLibrary());
  104.    app = this;
  105.  
  106.    //create the window
  107.    window = new MyAppWindow( this, &r );
  108.  
  109.    //Set the size
  110.    XRect rec(200,200, 300, 200);
  111.    window->SetSize( &rec );
  112. }
  113.  
  114.  
  115. void MyAppWindow :: Draw( void )
  116. {
  117.     FillBackground();
  118. }
  119.  
  120.  
  121. void main ( void)
  122. {
  123.     try
  124.    {
  125.       MyApp * app = new MyApp();  //create a new application
  126.    }
  127.     catch( XException& e)
  128.    {
  129.         XMessageBox( e.GetErrorMessage()); 
  130.         exit(-1);
  131.    }
  132.    app->Start();               //let the application work
  133. }
  134.