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

  1. #include "pm3.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. pm3Window :: pm3Window( XResource * r ): XFrameWindow( r, "pm3", 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( "pm3.hlp", GetProcess(), "pm3 - Help");
  29.    //associate the help with this function
  30.    help->AssociateWindow( this );HELP/
  31.  
  32.    //Activate the window
  33.    Activate();
  34. }
  35.  
  36.  
  37. pm3Window :: ~pm3Window()
  38. {
  39. }
  40.  
  41. //draw the window-content
  42. void pm3Window :: Draw( void )
  43. {
  44.    //fill the background
  45.    FillBackground( );
  46. }
  47.  
  48.  
  49. /* here the commands of the menu are posted */
  50. BOOL pm3Window :: 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.                           pm3 * thread = new pm3( (char*) fileName ); //start a new thread with the selected file(s)
  72.                           thread->Run();
  73.                        }
  74.                  }
  75.              }MENU/
  76.              break;
  77.          case IDM_SAVEAS:
  78. /MENU       {
  79.               
  80.                /*File/Open selected */
  81.                /* display the file-dialog defined by the system */
  82.                /* set the file-suffix and title of the dialog */
  83.                XFileDialog fileDlg(this, "*.TXT", NULL, NULL, FD_SAVEAS | FD_CENTER );
  84.  
  85.                /* the user selected a file */
  86.                if( fileDlg.GetCommand() == USER_OK)
  87.                  {
  88.                     XString fileName;
  89.                     fileDlg.GetFileName( &fileName);  //get filename and path where to save
  90.                     //perfor your save_as code here
  91.                  }
  92.             }MENU/
  93.             break;
  94. /MENU/HELP
  95.          case IDM_HELP_HELP:
  96.             help->ShowHelpForHelp();/HELP
  97.             break;
  98.          case IDM_HELP_INDEX:
  99.             help->ShowHelpIndex();
  100.             break;
  101.          case IDM_HELP_GENERAL:
  102.             help->ShowHelpForId( 100 );
  103.             break;HELP/ MENU/
  104.          default:
  105.             break;
  106.       }
  107.    return TRUE;
  108. }
  109.  
  110.  
  111. //here the control-events of our window-contents are posted
  112. void pm3Window :: DoControl( XControlEvent * event)
  113. {
  114.    switch( event->GetEventID())              //what type of event?
  115.       {
  116.          case WIN_CHANGED:                   //window-content changed!
  117.             {
  118.                switch( event->GetWindowID()) //which window posted the event?
  119.                   {
  120.                      default:
  121.                         break;               
  122.                   }
  123.             }
  124.       }
  125. }
  126.  
  127.  
  128. pm3 :: pm3(char * arg): XThread()
  129. {
  130.  
  131. }
  132.  
  133.  
  134. void pm3 :: Init( void )
  135. {
  136.    //create a resource wich is used to load the menu
  137.    resLib = new XResourceLibrary(this);
  138.    XResource r( IDM_MENU, resLib);
  139.  
  140.    //create the window
  141.    window = new pm3Window( &r );
  142. }
  143.  
  144.  
  145. int main ( int argc, void ** argv)
  146. {
  147.   if( argc > 1)  //there were arguments
  148.      {
  149.         SHORT i;
  150.         for(i=1; i < argc; i++)                           //we asume that every argument is a filename
  151.            {                                              // so we
  152.                pm3 * thread = new pm3( (char*) argv[i] ); //start for every filename a new thread
  153.                thread->Run();                             //let the thread run
  154.            }
  155.      }
  156.   else
  157.      {
  158.         pm3 * thread = new pm3();                //create a thread
  159.         thread->Run();                           //let the thread run
  160.      }
  161.  
  162.   XThread :: RunThreads();                       //let all threads work
  163.  
  164. }
  165.