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 >
Wrap
C/C++ Source or Header
|
1992-07-03
|
3KB
|
119 lines
// TVDIALOG.CPP
// Demonstrates use of TFileDialog to implement a file open
// or file save dialog box in a TVISION application.
#define Uses_TApplication
#define Uses_TKeys
#define Uses_TRect
#define Uses_TMenuBar
#define Uses_TSubMenu
#define Uses_TMenuItem
#define Uses_TStatusLine
#define Uses_TStatusItem
#define Uses_TStatusDef
#define Uses_TDeskTop
#define Uses_TFileDialog
#define Uses_TView
#include <tv.h>
#include <dos.h>
#include <string.h>
// This constant value is the ID returned for File ! Open cmd.
const int cmFile_Dialog = 200;
class DemoApp : public TApplication
{
public:
DemoApp();
static TStatusLine *initStatusLine( TRect r );
static TMenuBar *initMenuBar( TRect r );
virtual void handleEvent( TEvent& event);
};
DemoApp::DemoApp() :
TProgInit( &DemoApp::initStatusLine,
&DemoApp::initMenuBar,
&DemoApp::initDeskTop
)
// Constructor defaults to ancestor's constructor.
{
}
TStatusLine *DemoApp::initStatusLine(TRect r)
{
// Initializes the on screen status line.
r.a.y = r.b.y - 1;
return new TStatusLine( r,
*new TStatusDef( 0, 0xFFFF ) +
*new TStatusItem( 0, kbF10, cmMenu ) +
*new TStatusItem( "~Alt-X~ Exit", kbAltX, cmQuit )
);
}
TMenuBar *DemoApp::initMenuBar( TRect r )
{
// Initializes the menu bar and pulldown menu.
r.b.y = r.a.y + 1;
return new TMenuBar( r,
*new TSubMenu( "~F~ile", kbAltF )+
*new TMenuItem( "~O~pen", cmFile_Dialog, kbF3, hcNoContext, "F3" )+
newLine()+
*new TMenuItem( "E~x~it", cmQuit, cmQuit, hcNoContext, "Alt-X" )
);
}
// The following function is from Borland's TVEDIT example program
ushort execDialog( TDialog *d, void *data )
{
TView *p = TProgram::application->validView( d );
if( p == 0 )
return cmCancel;
else
{
if( data != 0 )
p->setData( data );
ushort result = TProgram::deskTop->execView( p );
if( result != cmCancel && data != 0 )
p->getData( data );
TObject::destroy( p );
return result;
}
}
void DemoApp::handleEvent(TEvent& event)
// Processes all event messages. Most messages are
// passed to TApplication for processing, but this
// function does handle the File | Open command and
// shows how to use the TFileDialog class.
{
char pathname[MAXPATH];
TApplication::handleEvent(event);
if( event.what == evCommand )
{
switch( event.message.command )
{
case cmFile_Dialog: {
// Set pathname to the default filename or wildcard pattern
// to first appear in the dialog box.
strcpy( pathname, "*.*" );
if ( execDialog( new TFileDialog( pathname, "Open File", "Filename",
fdOpenButton | fdHelpButton, 100 ), pathname) != cmCancel)
; // then open the file
break;
};
default:
return;
}
clearEvent( event );
}
}
int main( void )
{
DemoApp FileDlgDemo;
FileDlgDemo.run();
return 0;
}