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