home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / MASTER-1.ZIP / SOURCE / CHAP06 / CHAP06.LZH / TVDIALOG.CPP < prev    next >
C/C++ Source or Header  |  1992-07-03  |  3KB  |  119 lines

  1. // TVDIALOG.CPP
  2. // Demonstrates use of TFileDialog to implement a file open
  3. // or file save dialog box in a TVISION application.
  4. #define Uses_TApplication
  5. #define Uses_TKeys
  6. #define Uses_TRect
  7. #define Uses_TMenuBar
  8. #define Uses_TSubMenu
  9. #define Uses_TMenuItem
  10. #define Uses_TStatusLine
  11. #define Uses_TStatusItem
  12. #define Uses_TStatusDef
  13. #define Uses_TDeskTop
  14. #define Uses_TFileDialog
  15. #define Uses_TView
  16. #include <tv.h>
  17. #include <dos.h>
  18. #include <string.h>
  19.  
  20. // This constant value is the ID returned for File ! Open cmd.
  21. const int cmFile_Dialog = 200;
  22.  
  23. class DemoApp : public TApplication
  24. {
  25. public:
  26.   DemoApp();
  27.   static TStatusLine *initStatusLine( TRect r );
  28.   static TMenuBar *initMenuBar( TRect r );
  29.   virtual void handleEvent( TEvent& event);
  30. };
  31.  
  32. DemoApp::DemoApp() :
  33.   TProgInit( &DemoApp::initStatusLine,
  34.          &DemoApp::initMenuBar,
  35.          &DemoApp::initDeskTop
  36.        )
  37. // Constructor defaults to ancestor's constructor.
  38. {
  39. }
  40.  
  41. TStatusLine *DemoApp::initStatusLine(TRect r)
  42. {
  43. // Initializes the on screen status line.
  44.   r.a.y = r.b.y - 1;
  45.   return new TStatusLine( r,
  46.     *new TStatusDef( 0, 0xFFFF ) +
  47.        *new TStatusItem( 0, kbF10, cmMenu ) +
  48.        *new TStatusItem( "~Alt-X~ Exit", kbAltX, cmQuit )
  49.       );
  50. }
  51.  
  52. TMenuBar *DemoApp::initMenuBar( TRect r )
  53. {
  54. // Initializes the menu bar and pulldown menu.
  55.   r.b.y = r.a.y + 1;
  56.   return new TMenuBar( r,
  57.     *new TSubMenu( "~F~ile", kbAltF )+
  58.       *new TMenuItem( "~O~pen", cmFile_Dialog, kbF3, hcNoContext, "F3" )+
  59.       newLine()+
  60.       *new TMenuItem( "E~x~it", cmQuit, cmQuit, hcNoContext, "Alt-X" )
  61.     );
  62. }
  63.  
  64. // The following function is from Borland's TVEDIT example program
  65. ushort execDialog( TDialog *d, void *data )
  66. {
  67.     TView *p = TProgram::application->validView( d );
  68.     if( p == 0 )
  69.     return cmCancel;
  70.     else
  71.     {
  72.     if( data != 0 )
  73.         p->setData( data );
  74.     ushort result = TProgram::deskTop->execView( p );
  75.     if( result != cmCancel && data != 0 )
  76.         p->getData( data );
  77.     TObject::destroy( p );
  78.     return result;
  79.     }
  80. }
  81.  
  82.  
  83. void DemoApp::handleEvent(TEvent& event)
  84. // Processes all event messages.  Most messages are
  85. // passed to TApplication for processing, but this
  86. // function does handle the File | Open command and
  87. // shows how to use the TFileDialog class.
  88. {
  89.   char pathname[MAXPATH];
  90.  
  91.   TApplication::handleEvent(event);
  92.   if( event.what == evCommand )
  93.   {
  94.     switch( event.message.command )
  95.     {
  96.     case cmFile_Dialog: {
  97.       // Set pathname to the default filename or wildcard pattern
  98.       // to first appear in the dialog box.
  99.       strcpy( pathname, "*.*" );
  100.       if ( execDialog( new TFileDialog( pathname, "Open File", "Filename",
  101.        fdOpenButton | fdHelpButton, 100 ), pathname) != cmCancel)
  102.        ; // then open the file
  103.      break;
  104.        };
  105.     default:
  106.       return;
  107.     }
  108.     clearEvent( event );
  109.     }
  110. }
  111.  
  112.  
  113. int main( void )
  114. {
  115.   DemoApp FileDlgDemo;
  116.   FileDlgDemo.run();
  117.   return 0;
  118. }
  119.