home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / starview / examples / tutorial / example2 / example2.cxx < prev   
Encoding:
C/C++ Source or Header  |  1992-12-08  |  6.6 KB  |  286 lines

  1. /*******************************************************************
  2. *  EXAMPLE2.CXX
  3. *  (c) 1992 STAR DIVISION
  4. *******************************************************************/
  5.  
  6. #include <sv.hxx>
  7. #include <dir.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <io.h>
  11. #include <fcntl.h>
  12. #include <sys\stat.h>
  13.  
  14. #define MID_DLGBOXEN  10
  15. #define MID_DLGMES    11
  16. #define MID_DLGINFO   12
  17. #define MID_DLGWARN   13
  18. #define MID_DLGERR    14
  19. #define MID_DLGQUERY  15
  20. #define MID_ANFANG    20
  21. #define MID_VOR          30
  22. #define MID_RUECK     40
  23. #define MID_ENDE      50
  24.  
  25.  
  26. #define    TAXEDATEN    "TAXEABDA.NAM"
  27.  
  28. // --- class MyApp -------------------------------------------------
  29.  
  30. class MyApp : public Application
  31. {
  32. public:
  33.     virtual void Main( int, char*[] );
  34. };
  35.  
  36. // --- class MyWin -------------------------------------------------
  37.  
  38. class MyWin : public WorkWindow
  39. {
  40. private:
  41.     char    szTaxePfad [ MAXPATH ];        // Pfad auf Taxedatei
  42.     int            iOpened;            // Flag : Datei ge÷ffnet
  43.     int        iTaxeFd;            // Fieldescriptor
  44.  
  45.  
  46. public:
  47.                     MyWin();
  48.  
  49.     virtual BOOL    Close();
  50.  
  51.     void        Message( const String& rMessage );
  52. /*
  53.     virtual void    MouseButtonDown( const MouseEvent& rMEvt );
  54.     virtual void    MouseButtonUp( const MouseEvent& rMEvt );
  55.     virtual void    MouseMove( const MouseEvent& rMEvt );
  56. */
  57.  
  58.     long            DialogSelect( Menu* pMenu );
  59.     long            OperationSelect( Menu* pMenu );
  60. };
  61.  
  62. // --- MyWin::MyWin() ----------------------------------------------
  63.  
  64. MyWin::MyWin() : WorkWindow( NULL, WB_STDWORK | WB_APP )
  65. {
  66.   char    *cp = getenv( "TAXEPATH" );
  67.   if ( cp )
  68.   {
  69.     strcpy( szTaxePfad, cp );
  70.   }
  71.   else
  72.   {
  73.     Message( "Environmentvariable TAXEPATH nicht gesetzt" );
  74.     Close();                // Window erst gar nicht anzeigen
  75.     return;
  76.   }
  77.   iOpened = 0;                // Default : Datei nicht ge÷ffnet
  78.  
  79.   strcat( szTaxePfad, TAXEDATEN );      // Dateiname jetzt vollstΣndig
  80.   iTaxeFd = open( szTaxePfad, O_RDONLY  | O_BINARY,
  81.                   S_IREAD   | S_IWRITE );
  82.  
  83.   if ( iTaxeFd == -1 ) 
  84.   {
  85.     Message( "Fehler beim ╓ffnen der Taxedatei" );
  86.     Close();                // Window erst gar nicht anzeigen
  87.     return;
  88.   }
  89. }
  90.  
  91. // --- MyWin::Close() ----------------------------------------------
  92.  
  93. BOOL MyWin::Close()
  94. {
  95. /*
  96.     QueryBox aBox( this, WB_OK_CANCEL | WB_DEF_OK, "Exit Testprogramm" );
  97.  
  98.     if ( aBox.Execute() == RET_OK )
  99.         return WorkWindow::Close();
  100.     else
  101.         return FALSE;
  102. */
  103.     if ( iTaxeFd > 0 )
  104.       close( iTaxeFd );
  105.  
  106.     return WorkWindow::Close();
  107.  
  108. }
  109.  
  110. // --- MyWin::Message() ----------------------------------------------
  111.  
  112. void MyWin::Message( const String& rMessage )
  113. {
  114.     InfoBox aInfoBox( this,
  115.               rMessage );
  116.     aInfoBox.Execute();
  117. }
  118.  
  119.  
  120. // --- MyWin::MouseButtonDown() ------------------------------------
  121.  
  122. /*
  123. void MyWin::MouseButtonDown( const MouseEvent& rMEvt )
  124. {
  125.     CaptureMouse();
  126.     aLastPoint = rMEvt.GetPosPixel();
  127. }
  128.  
  129. // --- MyWin::MouseButtonUp() --------------------------------------
  130.  
  131. void MyWin::MouseButtonUp( const MouseEvent& )
  132. {
  133.     ReleaseMouse();
  134. }
  135.  
  136. // --- MyWin::MouseMove() ------------------------------------------
  137.  
  138. void MyWin::MouseMove( const MouseEvent& rMEvt )
  139. {
  140.     if ( rMEvt.GetMode() == MOUSE_SIMPLEDRAG )
  141.     {
  142.         DrawLine( aLastPoint, rMEvt.GetPosPixel() );
  143.         aLastPoint = rMEvt.GetPosPixel();
  144.     }
  145. }
  146. */
  147.  
  148. // --- MyWin::DialogSelect() ----------------------------------------
  149.  
  150. long MyWin::DialogSelect( Menu* pMenu )
  151. {
  152.     USHORT nItem;
  153.     nItem = pMenu->GetCurItemId();
  154.  
  155.     switch ( nItem )
  156.     {
  157.     case MID_DLGMES:
  158.         MessBox aMessBox( this,
  159.                   WinBits( WB_YES_NO_CANCEL ),
  160.                   "Message-Box",
  161.                   "Dies ist die Default-Message-Box\n"
  162.                   "aus der StarView-Klassenbibliothek" );
  163.         switch( aMessBox.Execute() )
  164.         {
  165.         case RET_OK :
  166.             ;
  167.             break;
  168.         }
  169.             break;
  170.  
  171.     case MID_DLGINFO:
  172.         InfoBox aInfoBox( this,
  173.                   "Dies ist die Default-Info-Box\n"
  174.                   "aus der StarView-Klassenbibliothek" );
  175.         aInfoBox.Execute();
  176.         break;
  177.  
  178.     case MID_DLGWARN:
  179.         WarningBox aWarnBox( this,
  180.                   WinBits( WB_YES_NO_CANCEL ),
  181.                   "Dies ist die Default-Warning-Box\n"
  182.                   "aus der StarView-Klassenbibliothek" );
  183.         switch( aWarnBox.Execute() )
  184.         {
  185.         case RET_OK :
  186.             ;
  187.             break;
  188.         }
  189.         break;
  190.  
  191.     case MID_DLGERR:
  192.         ErrorBox aErrorBox( this,
  193.                     WinBits( WB_YES_NO_CANCEL ),
  194.                 "Dies ist die Default-Error-Box\n"
  195.                     "aus der StarView-Klassenbibliothek" );
  196.         switch( aErrorBox.Execute() )
  197.         {
  198.         case RET_OK :
  199.             ;
  200.             break;
  201.         }
  202.         break;
  203.  
  204.         case MID_DLGQUERY:
  205.         QueryBox aQueryBox( this,
  206.                 WB_OK_CANCEL | WB_DEF_OK,
  207.                 "Dies ist die Default-Query-Box\n"
  208.                     "aus der StarView-Klassenbibliothek" );
  209.         aQueryBox.Execute();
  210.         break;
  211.     }
  212.  
  213.     return TRUE;
  214. }
  215.  
  216. // --- MyWin::OperationSelect() ----------------------------------------
  217.  
  218. long MyWin::OperationSelect( Menu* pMenu )
  219. {
  220.     USHORT nItem;
  221.     nItem = pMenu->GetCurItemId();
  222.  
  223.     Message( pMenu->GetItemText( nItem ) );
  224.  
  225.     switch ( nItem )
  226.     {
  227.     case MID_ANFANG:
  228.         break;
  229.     case MID_VOR:
  230.         break;
  231.     case MID_RUECK:
  232.         break;
  233.     case MID_ENDE:
  234.         break;
  235.     }
  236.     return TRUE;
  237. }
  238.  
  239. // --- MyApp::Main() -----------------------------------------------
  240.  
  241. void MyApp::Main( int, char*[] )
  242. {
  243.     MyWin       aMainWin;
  244.  
  245.     PopupMenu   aDialogMenu;
  246.     MenuBar     aMenuBar;
  247.  
  248.     aMenuBar.InsertItem( MID_DLGBOXEN, "~Dialogboxen" );
  249.     aMenuBar.InsertItem( MID_ANFANG, "~Anfang" );
  250.     aMenuBar.InsertItem( MID_VOR,    "~Vor"    );
  251.     aMenuBar.InsertItem( MID_RUECK,  "~Rⁿck"   );
  252.     aMenuBar.InsertItem( MID_ENDE,   "~Ende"   );
  253.  
  254.     aMenuBar.ChangePopupMenu( MID_DLGBOXEN, &aDialogMenu );
  255.  
  256.     aDialogMenu.InsertItem( MID_DLGMES,   "~Message" );
  257.     aDialogMenu.InsertItem( MID_DLGINFO,  "~Info"    );
  258.     aDialogMenu.InsertItem( MID_DLGWARN,  "~Warning" );
  259.     aDialogMenu.InsertItem( MID_DLGERR,   "~Error"   );
  260.     aDialogMenu.InsertItem( MID_DLGQUERY, "~Query"   );
  261.  
  262.  
  263.     aDialogMenu.PushSelectHdl( LINK( &aMainWin,
  264.                                     MyWin::DialogSelect ) );
  265.  
  266.     aMenuBar.PushSelectHdl( LINK( &aMainWin,
  267.                  MyWin::OperationSelect ) );
  268.  
  269.     ChangeAppMenu( &aMenuBar );
  270.  
  271.     aMainWin.SetText( "2.Beipiel mit StarView ( EXAMPLE2 )" );
  272.     aMainWin.Show();
  273.  
  274. //    aMainWin.Minimize();            // minimieren
  275.  
  276.     Execute();
  277. }
  278.  
  279. // --- aMyApp ------------------------------------------------------
  280.  
  281. MyApp aMyApp;
  282.  
  283. #ifdef MAC
  284.     Application* pApp = &aMyApp;
  285. #endif
  286.