home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tv20os2.zip / test / hello.cpp next >
Text File  |  1999-06-11  |  3KB  |  111 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 <tvision/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. protected:
  38.     void greetingBox();
  39. };
  40.  
  41. THelloApp::THelloApp() :
  42.     TProgInit( &THelloApp::initStatusLine,
  43.                &THelloApp::initMenuBar,
  44.                &THelloApp::initDeskTop
  45.              )
  46. {
  47. }
  48.  
  49. void THelloApp::greetingBox()
  50. {
  51.     TDialog *d = new TDialog(TRect( 25, 5, 55, 16 ), "Hello World!" );
  52.  
  53.     d->insert( new TStaticText( TRect( 3, 5, 15, 6 ), "Who are you?" ) );
  54.     d->insert( new TButton( TRect( 16, 2, 28, 4 ), "Terrific", cmCancel, bfNormal ) );
  55.     d->insert( new TButton( TRect( 16, 4, 28, 6 ), "Ok", cmCancel, bfNormal ) );
  56.     d->insert( new TButton( TRect( 16, 6, 28, 8 ), "Lousy", cmCancel, bfNormal ) );
  57.     d->insert( new TButton( TRect( 16, 8, 28, 10 ), "Cancel", cmCancel, bfNormal ) );
  58.  
  59.     deskTop->execView( d );
  60.     destroy(d);
  61. }
  62.  
  63. void THelloApp::handleEvent( TEvent& event )
  64. {
  65.     TApplication::handleEvent( event );
  66.     if( event.what == evCommand )
  67.         {
  68.         switch( event.message.command )
  69.             {
  70.             case GreetThemCmd:
  71.                 greetingBox();
  72.                 clearEvent( event );
  73.                 break;
  74.             default:
  75.                 break;
  76.             }
  77.         }
  78. }
  79.  
  80. TMenuBar *THelloApp::initMenuBar( TRect r )
  81. {
  82.  
  83.     r.b.y = r.a.y+1;
  84.  
  85.     return new TMenuBar( r,
  86.       *new TSubMenu( "~H~ello", kbAltH ) +
  87.         *new TMenuItem( "~G~reeting...", GreetThemCmd, kbAltG ) +
  88.          newLine() +
  89.         *new TMenuItem( "E~x~it", cmQuit, cmQuit, hcNoContext, "Alt-X" )
  90.         );
  91.  
  92. }
  93.  
  94. TStatusLine *THelloApp::initStatusLine( TRect r )
  95. {
  96.     r.a.y = r.b.y-1;
  97.     return new TStatusLine( r,
  98.         *new TStatusDef( 0, 0xFFFF ) +
  99.             *new TStatusItem( "~Alt-X~ Exit", kbAltX, cmQuit ) +
  100.             *new TStatusItem( 0, kbF10, cmMenu )
  101.             );
  102. }
  103.  
  104. int main()
  105. {
  106.     cerr << " " << endl;
  107.     THelloApp helloWorld;
  108.     helloWorld.run();
  109.     return 0;
  110. }
  111.