home *** CD-ROM | disk | FTP | other *** search
- //========================================================================
- // The following example routines have been provided by the Technical
- // Support staff at Borland International. They are provided as a
- // courtesy and not as part of a Borland product, and as such, are
- // provided without the assurance of technical support or any specific
- // guarantees.
- //========================================================================
- // Turbo Vision - Shelling to DOS
- //
- // - This sample code demonstrates shelling to DOS from a TV application.
- //------------------------------------------------------------------------
- #define Uses_TApplication
- #define Uses_TBackground
- #define Uses_TButton
- #define Uses_TKeys
- #define Uses_TDeskTop
- #define Uses_TDialog
- #define Uses_TMenu
- #define Uses_TMenuBar
- #define Uses_TMenuItem
- #define Uses_TRect
- #define Uses_TStaticText
- #define Uses_TStatusDef
- #define Uses_TStatusItem
- #define Uses_TStatusLine
- #include <tv.h>
- #include <stdlib.h>
- #include <conio.h>
-
- //========================================================================
- // global data
- //------------------------------------------------------------------------
- const cmAbout = 100; // User selected menu item 'About'
- const cmShell = 101; // User selected menu item 'Shell'
-
- //========================================================================
- // class definitions
- //------------------------------------------------------------------------
- class TApp : public TApplication {
- // main application class
-
- public:
- TApp();
-
- // virtual functions to be locally redefined
- static TMenuBar *initMenuBar( TRect r );
- void handleEvent( TEvent &event );
-
- // declare new functions
- void AboutDialog();
- };
-
- //========================================================================
- // implementation of TApp
- //------------------------------------------------------------------------
- TApp::TApp() : TProgInit( &TApp::initStatusLine,
- &TApp::initMenuBar, &TApp::initDeskTop )
- {
- }
-
- //------------------------------------------------------------------------
- // define menu bar
- //------------------------------------------------------------------------
- TMenuBar *TApp::initMenuBar( TRect r )
- {
- r.b.y = r.a.y + 1;
- return( new TMenuBar( r, new TMenu(
- *new TMenuItem( "~A~bout", cmAbout, kbAltA, hcNoContext, 0,
- new TMenuItem( "~D~os Shell", cmShell, kbAltZ, hcNoContext, 0 )
- ) ) ) );
- }
-
- //------------------------------------------------------------------------
- // event-handler
- //------------------------------------------------------------------------
- void TApp::handleEvent( TEvent &event )
- {
- TApplication::handleEvent( event );
- if( event.what == evCommand )
- {
- switch( event.message.command )
- {
- case cmAbout: // display about box
- AboutDialog();
- clearEvent( event );
- break;
- case cmShell: // shell to DOS
- // invoke TProgram::suspend() to safely
- // interrupt the program execution
- suspend();
-
- clrscr();
- cout << "Type EXIT to return...";
-
- // shell by calling the command processor
- system( getenv( "COMSPEC" ) );
-
- // restart the TV application
- resume();
-
- // redraw the TV screen
- redraw();
-
- clearEvent( event );
- break;
- }
- }
- }
-
- //------------------------------------------------------------------------
- // create modal About dialog box
- //------------------------------------------------------------------------
- void TApp::AboutDialog()
- {
- // remind us of the purpose of the example
- TDialog *pd = new TDialog( TRect( 0, 0, 35, 12 ), "About" );
- if( pd )
- {
- pd->options |= ofCentered;
- pd->insert( new TStaticText( TRect( 1, 2, 34, 7 ),
- "\003Turbo Vision Example\n\003\n"
- "\003Shelling to DOS\n\003\n"
- "\003Borland Technical Support" ) );
- pd->insert( new TButton( TRect( 3, 9, 32, 11 ), "~O~k",
- cmOK, bfDefault ) );
- deskTop->execView( pd );
- }
- destroy( pd );
- }
-
- //========================================================================
- int main(void)
- {
- // now for the tought stuff
- TApp myApp;
- myApp.run();
- return 0;
- }
-