home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 15.ddi / TVDOCDEM.ZIP / TVGUID04.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  4.0 KB  |  139 lines

  1. /*---------------------------------------------------------*/
  2. /*                                                         */
  3. /*   Turbo Vision 1.0                                      */
  4. /*   TVGUID04 Demo Source File                             */
  5. /*   Copyright (c) 1991 by Borland International           */
  6. /*                                                         */
  7. /*---------------------------------------------------------*/
  8.  
  9. #include <stdlib.h>               // for random()
  10.  
  11. #define Uses_TEvent
  12. #define Uses_TApplication
  13. #define Uses_TKeys
  14. #define Uses_TRect
  15. #define Uses_TMenuBar
  16. #define Uses_TSubMenu
  17. #define Uses_TMenuItem
  18. #define Uses_TStatusLine
  19. #define Uses_TStatusItem
  20. #define Uses_TStatusDef
  21. #define Uses_TDeskTop
  22. #define Uses_TWindow
  23. #include <tv.h>
  24.  
  25. const int cmMyFileOpen = 200; // assign new command values
  26. const int cmMyNewWin   = 201;
  27.  
  28.  
  29. class TMyApp : public TApplication
  30. {
  31.  
  32. public:
  33.     TMyApp();
  34.     static TStatusLine *initStatusLine( TRect r );
  35.     static TMenuBar *initMenuBar( TRect r );
  36.     virtual void handleEvent( TEvent& event);
  37.     void myNewWindow();
  38. };
  39.  
  40.  
  41. static short winNumber = 0;          // initialize window number
  42.  
  43. class TDemoWindow : public TWindow   // define a new window class
  44. {
  45.  
  46. public:
  47.  
  48.    TDemoWindow( const TRect& r, const char *aTitle, short aNumber );
  49.     // declare a constructor
  50.  
  51.     //   static TFrame *initFrame( TRect r );
  52.     // override needed only if you want a nonstandard frame
  53.     // Here we'll inherit TWindow::initFrame unchanged
  54.     // so TWindowInit will take &TDemoWindow::initFrame to give
  55.     // a standard frame
  56.  
  57. };
  58.  
  59.  
  60. TMyApp::TMyApp() :
  61.     TProgInit( &TMyApp::initStatusLine,
  62.                &TMyApp::initMenuBar,
  63.                &TMyApp::initDeskTop
  64.              )
  65. {
  66. }
  67.  
  68. TStatusLine *TMyApp::initStatusLine(TRect r)
  69. {
  70.     r.a.y = r.b.y - 1;     // move top to 1 line above bottom
  71.     return new TStatusLine( r,
  72.         *new TStatusDef( 0, 0xFFFF ) +
  73.         // set range of help contexts
  74.             *new TStatusItem( 0, kbF10, cmMenu ) +
  75.             // define an item
  76.             *new TStatusItem( "~Alt-X~ Exit", kbAltX, cmQuit ) +
  77.             // define an item
  78.             *new TStatusItem( "~Alt-F3~ Close", kbAltF3, cmClose )
  79.             // and another one
  80.         );
  81. }
  82.  
  83. TMenuBar *TMyApp::initMenuBar( TRect r )
  84. {
  85.  
  86.     r.b.y = r.a.y + 1;    // set bottom line 1 line below top line
  87.     return new TMenuBar( r,
  88.         *new TSubMenu( "~F~ile", kbAltF )+
  89.             *new TMenuItem( "~O~pen", cmMyFileOpen, kbF3, hcNoContext, "F3" )+
  90.             *new TMenuItem( "~N~ew",  cmMyNewWin,   kbF4, hcNoContext, "F4" )+
  91.             newLine()+
  92.             *new TMenuItem( "E~x~it", cmQuit, cmQuit, hcNoContext, "Alt-X" )+
  93.         *new TSubMenu( "~W~indow", kbAltW )+
  94.             *new TMenuItem( "~N~ext", cmNext,     kbF6, hcNoContext, "F6" )+
  95.             *new TMenuItem( "~Z~oom", cmZoom,     kbF5, hcNoContext, "F5" )
  96.         );
  97. }
  98.  
  99. void TMyApp::handleEvent(TEvent& event)
  100. {
  101.     TApplication::handleEvent(event); // act like base!
  102.     if( event.what == evCommand )
  103.         {
  104.         switch( event.message.command )
  105.             {
  106.             case cmMyNewWin:       // but respond to additional commands
  107.                 myNewWindow();     // define action for cmMyNewWin
  108.                 break;
  109.             default:
  110.                 return;
  111.             }
  112.         clearEvent( event );       // clear event after handling
  113.         }
  114. }
  115.  
  116. void TMyApp::myNewWindow()
  117. {
  118.     TRect r( 0, 0, 26, 7 );           // set initial size and position
  119.     r.move( random(53), random(16) ); // randomly move around screen
  120.     TDemoWindow *window = new TDemoWindow ( r, "Demo Window", ++winNumber);
  121.     deskTop->insert(window); // put window into desktop and draw it
  122. }
  123.  
  124.  
  125. TDemoWindow::TDemoWindow( const TRect& r, const char *aTitle, short aNumber):
  126.                           TWindow( r, aTitle, aNumber),
  127.                           TWindowInit( &TDemoWindow::initFrame
  128.                         )
  129.  
  130. {
  131. }
  132.  
  133. int main()
  134. {
  135.     TMyApp myApp;
  136.     myApp.run();
  137.     return 0;
  138. }
  139.