home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_progs
/
prog_c
/
filrqstr.lzh
/
FILEREQUESTER
/
GFDEMO.C
< prev
Wrap
C/C++ Source or Header
|
1991-11-01
|
5KB
|
154 lines
/*****
Demo Program for using FILE NAME REQUESTER
This program shows how to use the file name requester, getfil.o
(c) 1986 by MicroSmiths, Inc.
Permission is granted to use the object code routine 'getfile' in any
Amiga program, commercial or otherwise, EXCEPT that it shall NOT BE
used in any Text Editor, and it shall NOT BE SOLD as an OBJECT MODULE
or in a LIBRARY.
This program is used with the Object Code file, 'getfil.o',
to provide a file name requester. The object code file is posted
in the 'listings' area.
The object code file will need to be truncated if you got these
two files via modem. The correct size for 'getfile.o' is 5680 bytes.
This program will compile using the Lattice 'C' compiler. The program
is linked with the command shown below:
Alink df1:lib/lstartup.obj,gfdemo.o,getfile.o LIB df1:lib/lc.lib,df1:lib/amiga.lib TO gfdemo
The basic call is:
getfile(Window,Hailing_string,file_name,directory_name);
Where:
Window is a pointer to your window
Hailing_string is a prompt displayed in the requester
file_name is a text array which will be altered by getfile,
it returns the file name.
directory_name is a text array altered by getfile, it
is the directory.
The return value is either a pointer to your buffer, file_name,
or NULL if the user selected CANCEL.
You must reserve two text areas for file and directory like so:
TEXT file_name[34];
TEXT dir_name[67]
Please, if you find any bugs in getfil.o, let us know ASAP so
we can update this file.
************************************************************************/
#include <exec/types.h>
#include <exec/devices.h>
#include <intuition/intuition.h>
struct IntuitionBase *IntuitionBase; /* Handles for inutition and */
struct GfxBase *GfxBase; /* graphics libraries */
/************************************************************************/
/* You supply two string buffers, for the filename and directory name */
/* You may pre-initialize them to any string you want. */
/************************************************************************/
#define FNAME_SIZE 33
TEXT file_name[FNAME_SIZE+1];
TEXT dir_name[FNAME_SIZE+FNAME_SIZE+1];
struct Window *p_Window; /* Handle for window we open */
/* Struct to open Window */
struct NewWindow NewWindow = {
10,10,400,150, 2,1, /* Left,Top, Width,Height, Pens */
MOUSEBUTTONS | MOUSEMOVE | MENUPICK | CLOSEWINDOW, /* IDCMP flags */
SMART_REFRESH | ACTIVATE | WINDOWSIZING | WINDOWCLOSE |
WINDOWDRAG | WINDOWDEPTH | REPORTMOUSE, /* Window flags */
NULL, NULL, /* First Gadget, Checkmark image */
(UBYTE *)"MicroSmiths Requester Demo", /* Window Title */
NULL, NULL, /* Screen and BitMap */
100,60, 32767,32767, /* Window Sizing limits */
WBENCHSCREEN}; /* WBENCH or CUSTOMSCREEN */
/* Menu description */
struct IntuiText menu_text = { 2,1,JAM2, 20,1, NULL, (UBYTE *)"Open",NULL };
struct MenuItem menu_item = {
NULL, 0,10,100,10, /* Next item, Left, Top, Width, Height */
HIGHCOMP | ITEMENABLED | ITEMTEXT | COMMSEQ,
NULL,(APTR)&menu_text, /* MutualExclude, ItemFill */
NULL, 'Q', NULL }; /* SelectFill, Command , SubItem */
struct Menu simple_menu = {
NULL, 0,0,60,10, MENUENABLED, "Menu", &menu_item };
/****************************************************************/
/* init_window() */
/* Opens Window, sets up menu strip and I/O Port */
/****************************************************************/
init_window()
{
if ( ! (IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library",29)) ||
! (GfxBase =(struct GfxBase *)OpenLibrary("graphics.library",29)) )
exit(20);
/* Open the window, sets handle p_Window */
if ( ! (p_Window = (struct Window *)OpenWindow( &NewWindow )) ) {
CloseLibrary(GfxBase); CloseLibrary(IntuitionBase);
exit(20);
}
SetMenuStrip( p_Window, &simple_menu );
}
/***************************************************************/
/* clear_window */
/* Clears window and screen set up by init_window */
/***************************************************************/
clear_window()
{
ClearMenuStrip(p_Window);
CloseWindow(p_Window);
}
/*** Main: Open window, process inputs , close window ***/
main()
{
struct IntuiMessage *message; /* Gets input event */
int class,code; /* Event information */
BOOL quit_flag; /* Application flags */
init_window(); /* Open the window */
for ( quit_flag = FALSE; ! quit_flag ; ) {
while (! (message=(struct IntuiMessage *)GetMsg(p_Window->UserPort)) )
WaitPort( p_Window->UserPort ); /* Wait for input event */
class = message->Class; code = message->Code; /* Get event info */
ReplyMsg( message ); /* Tell intuition we're through with event */
switch ( class ) { /* Process the input event */
case CLOSEWINDOW: quit_flag = TRUE;
break;
/* Heres what you're looking for... */
case MENUPICK:
if ( (MENUNUM( code ) == 0) && (ITEMNUM( code ) == 0) ) {
/* Call up the filename requester */
if ( get_fname(p_Window, "Your String Here",file_name,dir_name) )
printf("Got name %s directory %s\n",file_name,dir_name);
else
printf("User aborted getfile request\n");
}
}
}
clear_window(); /* Return all resources and exit */
}