home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool_main.zip / ool / samples / sample14 / sample14.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-02  |  2.6 KB  |  110 lines

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