home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / owf.zip / template / pm1 / pm1.cpp < prev    next >
C/C++ Source or Header  |  1997-02-14  |  4KB  |  145 lines

  1. #include "pm1.h"
  2.  
  3. #include XRect_i
  4. #include XString_i
  5. #include XMenuBar_i
  6. #include XControlEvent_i
  7. #include XResourceLibrary_i
  8. #include XFileDialog_i
  9. #include XColor_i
  10.  
  11. #include <stdlib.h>
  12.  
  13.  
  14. //create a window out of the resource-file, the last parameter tells the library
  15. //to build the window with the ID given in XResource. 
  16. pm1Window :: pm1Window( XResource * r ): XFrameWindow( r, "pm1", XFrameWindow::defaultStyle | FRM_ICON | FRM_TASKLIST | FRM_CENTER /MENU | FRM_MENU | FRM_ACCELTABLEMENU/)
  17. {
  18.    //Set background-color
  19.    XColor color( COL_WHITE);
  20.    SetBackgroundColor( &color );
  21.  
  22.    //Set size
  23.    XRect rect( 100,100, 400, 300);
  24.    SetSize(&rect);
  25.  
  26. /HELP
  27.    //create a helpinstance
  28.    help = new XHelpInstance( "pm1.hlp", GetProcess(), "pm1 - Help");
  29.    //associate the help with this function
  30.    help->AssociateWindow( this );HELP/
  31.  
  32.    //Activate the window
  33.    Activate();
  34. }
  35.  
  36.  
  37. pm1Window :: ~pm1Window()
  38. {
  39. }
  40.  
  41. //draw the window-content
  42. void pm1Window :: Draw( void )
  43. {
  44.    //fill the background
  45.    FillBackground( );
  46. }
  47.  
  48.  
  49. /* here the commands of the menu are posted */
  50. BOOL pm1Window :: DoCommand( LONG command)
  51. {
  52.    switch( command )
  53.       {
  54.          //which menuitem was selected?
  55.          case IDM_OPEN:
  56. /MENU       {
  57.               
  58.                /*File/Open selected */
  59.                /* display the file-dialog defined by the system */
  60.                /* set the file-suffix and title of the dialog */
  61.                XFileDialog fileDlg(this, "*.TXT", NULL, NULL, FD_OPEN | FD_CENTER | FD_MULTIPLESEL);
  62.  
  63.                /* the user selected a file */
  64.                if( fileDlg.GetCommand() == USER_OK)
  65.                  {
  66.                     XString fileName;
  67.                     SHORT i, files = fileDlg.GetFileCount();  //how much files are selected?
  68.                     for(i=0; i < files; i++)
  69.                        {
  70.                           fileDlg.GetFileName( &fileName, i );  //get filename and path for every file
  71.                           //perfor your loading of the selected file(s) here
  72.                        }
  73.                  }
  74.              }MENU/
  75.              break;
  76.          case IDM_SAVEAS:
  77. /MENU       {
  78.               
  79.                /*File/Open selected */
  80.                /* display the file-dialog defined by the system */
  81.                /* set the file-suffix and title of the dialog */
  82.                XFileDialog fileDlg(this, "*.TXT", NULL, NULL, FD_SAVEAS | FD_CENTER );
  83.  
  84.                /* the user selected a file */
  85.                if( fileDlg.GetCommand() == USER_OK)
  86.                  {
  87.                     XString fileName;
  88.                     fileDlg.GetFileName( &fileName);  //get filename and path where to save
  89.                     //perfor your save_as code here
  90.                  }
  91.             }MENU/
  92.             break;
  93. /MENU/HELP
  94.          case IDM_HELP_HELP:
  95.             help->ShowHelpForHelp();/HELP
  96.             break;
  97.          case IDM_HELP_INDEX:
  98.             help->ShowHelpIndex();
  99.             break;
  100.          case IDM_HELP_GENERAL:
  101.             help->ShowHelpForId( 100 );
  102.             break;HELP/ MENU/
  103.          default:
  104.             break;
  105.       }
  106.    return TRUE;
  107. }
  108.  
  109.  
  110. //here the control-events of our window-contents are posted
  111. void pm1Window :: DoControl( XControlEvent * event)
  112. {
  113.    switch( event->GetEventID())              //what type of event?
  114.       {
  115.          case WIN_CHANGED:                   //window-content changed!
  116.             {
  117.                switch( event->GetWindowID()) //which window posted the event?
  118.                   {
  119.                      default:
  120.                         break;               
  121.                   }
  122.             }
  123.       }
  124. }
  125.  
  126.  
  127. pm1 :: pm1(): XApplication()
  128. {
  129.    //create a resource wich is used to load the menu
  130.    XResource r( IDM_MENU, GetResourceLibrary());
  131.  
  132.    //create the window
  133.    window = new pm1Window( &r );
  134. }
  135.  
  136.  
  137. void main ( void)
  138. {
  139.    //create a new application
  140.    pm1 * app = new pm1();  
  141.  
  142.    //let the application work
  143.    app->Start();               
  144. }
  145.