home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / tvision / shell / dosshell.cpp
Encoding:
C/C++ Source or Header  |  1991-10-10  |  4.5 KB  |  139 lines

  1. //========================================================================
  2. //  The following example routines have been provided by the Technical
  3. //  Support staff at Borland International.  They are provided as a
  4. //  courtesy and not as part of a Borland product, and as such, are
  5. //  provided without the assurance of technical support or any specific
  6. //  guarantees.
  7. //========================================================================
  8. //  Turbo Vision - Shelling to DOS
  9. //
  10. //  - This sample code demonstrates shelling to DOS from a TV application.
  11. //------------------------------------------------------------------------
  12. #define Uses_TApplication
  13. #define Uses_TBackground
  14. #define Uses_TButton
  15. #define Uses_TKeys
  16. #define Uses_TDeskTop
  17. #define Uses_TDialog
  18. #define Uses_TMenu
  19. #define Uses_TMenuBar
  20. #define Uses_TMenuItem
  21. #define Uses_TRect
  22. #define Uses_TStaticText
  23. #define Uses_TStatusDef
  24. #define Uses_TStatusItem
  25. #define Uses_TStatusLine
  26. #include <tv.h>
  27. #include <stdlib.h>
  28. #include <conio.h>
  29.  
  30. //========================================================================
  31. //  global data
  32. //------------------------------------------------------------------------
  33. const cmAbout   = 100;  // User selected menu item 'About'
  34. const cmShell   = 101;  // User selected menu item 'Shell'
  35.  
  36. //========================================================================
  37. //  class definitions
  38. //------------------------------------------------------------------------
  39. class TApp : public TApplication {
  40.     //  main application class
  41.  
  42. public:
  43.     TApp();
  44.  
  45.     // virtual functions to be locally redefined
  46.     static TMenuBar *initMenuBar( TRect r );
  47.     void handleEvent( TEvent &event );
  48.  
  49.     // declare new functions
  50.     void AboutDialog();
  51. };
  52.  
  53. //========================================================================
  54. //  implementation of TApp
  55. //------------------------------------------------------------------------
  56. TApp::TApp() : TProgInit( &TApp::initStatusLine,
  57.                     &TApp::initMenuBar, &TApp::initDeskTop )
  58. {
  59. }
  60.  
  61. //------------------------------------------------------------------------
  62. // define menu bar
  63. //------------------------------------------------------------------------
  64. TMenuBar *TApp::initMenuBar( TRect r )
  65. {
  66.     r.b.y = r.a.y + 1;
  67.     return( new TMenuBar( r, new TMenu(
  68.         *new TMenuItem( "~A~bout", cmAbout, kbAltA, hcNoContext, 0,
  69.         new TMenuItem( "~D~os Shell", cmShell, kbAltZ, hcNoContext, 0 )
  70.         ) ) ) );
  71. }
  72.  
  73. //------------------------------------------------------------------------
  74. // event-handler
  75. //------------------------------------------------------------------------
  76. void TApp::handleEvent( TEvent &event )
  77. {
  78.     TApplication::handleEvent( event );
  79.     if( event.what == evCommand )
  80.     {
  81.         switch( event.message.command )
  82.         {
  83.             case cmAbout:       // display about box
  84.                 AboutDialog();
  85.                 clearEvent( event );
  86.                 break;
  87.             case cmShell:       // shell to DOS
  88.                 // invoke TProgram::suspend() to safely
  89.                 // interrupt the program execution
  90.                 suspend();
  91.  
  92.                 clrscr();
  93.                 cout << "Type EXIT to return...";
  94.  
  95.                 // shell by calling the command processor
  96.                 system( getenv( "COMSPEC" ) );
  97.  
  98.                 // restart the TV application
  99.                 resume();
  100.  
  101.                 // redraw the TV screen
  102.                 redraw();
  103.  
  104.                 clearEvent( event );
  105.                 break;
  106.         }
  107.     }
  108. }
  109.  
  110. //------------------------------------------------------------------------
  111. // create modal About dialog box
  112. //------------------------------------------------------------------------
  113. void TApp::AboutDialog()
  114. {
  115.     // remind us of the purpose of the example
  116.     TDialog *pd = new TDialog( TRect( 0, 0, 35, 12 ), "About" );
  117.     if( pd )
  118.     {
  119.         pd->options |= ofCentered;
  120.         pd->insert( new TStaticText( TRect( 1, 2, 34, 7 ),
  121.                 "\003Turbo Vision Example\n\003\n"
  122.                 "\003Shelling to DOS\n\003\n"
  123.                 "\003Borland Technical Support" ) );
  124.         pd->insert( new TButton( TRect( 3, 9, 32, 11 ), "~O~k",
  125.                                 cmOK, bfDefault ) );
  126.         deskTop->execView( pd );
  127.     }
  128.     destroy( pd );
  129. }
  130.  
  131. //========================================================================
  132. int main(void)
  133. {
  134.     // now for the tought stuff
  135.     TApp myApp;
  136.     myApp.run();
  137.     return 0;
  138. }
  139.