home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 2.ddi / TVDEMOS.ZIP / HELLO.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  2.9 KB  |  112 lines

  1. /*---------------------------------------------------------*/
  2. /*                                                         */
  3. /*   Turbo Vision 1.0                                      */
  4. /*   Copyright (c) 1991 by Borland International           */
  5. /*                                                         */
  6. /*   Turbo Vision Hello World Demo Source File             */
  7. /*---------------------------------------------------------*/
  8.  
  9. #define Uses_TKeys
  10. #define Uses_TApplication
  11. #define Uses_TEvent
  12. #define Uses_TRect
  13. #define Uses_TDialog
  14. #define Uses_TStaticText
  15. #define Uses_TButton
  16. #define Uses_TMenuBar
  17. #define Uses_TSubMenu
  18. #define Uses_TMenuItem
  19. #define Uses_TStatusLine
  20. #define Uses_TStatusItem
  21. #define Uses_TStatusDef
  22. #define Uses_TDeskTop
  23. #include <tv.h>
  24.  
  25. const GreetThemCmd = 100;
  26.  
  27. class THelloApp : public TApplication
  28. {
  29.  
  30. public:
  31.  
  32.     THelloApp();
  33.  
  34.     virtual void handleEvent( TEvent& event );
  35.     static TMenuBar *initMenuBar( TRect );
  36.     static TStatusLine *initStatusLine( TRect );
  37.  
  38. private:
  39.  
  40.     void greetingBox();
  41. };
  42.  
  43. THelloApp::THelloApp() :
  44.     TProgInit( &THelloApp::initStatusLine,
  45.                &THelloApp::initMenuBar,
  46.                &THelloApp::initDeskTop
  47.              )
  48. {
  49. }
  50.  
  51. void THelloApp::greetingBox()
  52. {
  53.     TDialog *d = new TDialog(TRect( 25, 5, 55, 16 ), "Hello, World!" );
  54.  
  55.     d->insert( new TStaticText( TRect( 3, 5, 15, 6 ), "How are you?" ) );
  56.     d->insert( new TButton( TRect( 16, 2, 28, 4 ), "Terrific", cmCancel, bfNormal ) );
  57.     d->insert( new TButton( TRect( 16, 4, 28, 6 ), "Ok", cmCancel, bfNormal ) );
  58.     d->insert( new TButton( TRect( 16, 6, 28, 8 ), "Lousy", cmCancel, bfNormal ) );
  59.     d->insert( new TButton( TRect( 16, 8, 28, 10 ), "Cancel", cmCancel, bfNormal ) );
  60.  
  61.     deskTop->execView( d );
  62.     destroy(d);
  63. }
  64.  
  65. void THelloApp::handleEvent( TEvent& event )
  66. {
  67.     TApplication::handleEvent( event );
  68.     if( event.what == evCommand )
  69.         {
  70.         switch( event.message.command )
  71.             {
  72.             case GreetThemCmd:
  73.                 greetingBox();
  74.                 clearEvent( event );
  75.                 break;
  76.             default:
  77.                 break;
  78.             }
  79.         }
  80. }
  81.  
  82. TMenuBar *THelloApp::initMenuBar( TRect r )
  83. {
  84.  
  85.     r.b.y = r.a.y+1;
  86.  
  87.     return new TMenuBar( r,
  88.       *new TSubMenu( "~H~ello", kbAltH ) +
  89.         *new TMenuItem( "~G~reeting...", GreetThemCmd, kbAltG ) +
  90.          newLine() +
  91.         *new TMenuItem( "E~x~it", cmQuit, cmQuit, hcNoContext, "Alt-X" )
  92.         );
  93.  
  94. }
  95.  
  96. TStatusLine *THelloApp::initStatusLine( TRect r )
  97. {
  98.     r.a.y = r.b.y-1;
  99.     return new TStatusLine( r,
  100.         *new TStatusDef( 0, 0xFFFF ) +
  101.             *new TStatusItem( "~Alt-X~ Exit", kbAltX, cmQuit ) +
  102.             *new TStatusItem( 0, kbF10, cmMenu )
  103.             );
  104. }
  105.  
  106. int main()
  107. {
  108.     THelloApp helloWorld;
  109.     helloWorld.run();
  110.     return 0;
  111. }
  112.