home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Pier Shareware 6
/
The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso
/
035
/
cenvi29.zip
/
FILEDLG.LIB
< prev
next >
Wrap
Text File
|
1994-03-08
|
6KB
|
132 lines
// FileDlg.lib - Cmm code wrapper for a simple implementation of the
// ver.1 WinFileDlg() function found in PM.You may #include
// this file in your CMM source to have access to this
// version of WinFileDlg().
// FileDialog([MatchingFileSpec[,Title[,Flags[,OKButtonText]]]])
// MatchingFileSpec: string file specification, including wildcard in the
// file name. For example "C:\\DATA\\*.TXT" or
// "*.INI". If this is not supplied or if it is
// NULL then * will be the default.
// Title: String to be the title of the open dialog box.
// Flags: Or of flags describing dialog box type and behavior. If none
// or 0 specified then defaults to: FDS_OPEN_DIALOG | FDS_CENTER
// Note that FDS_OPEN_DIALOG or FDS_SAVEAS_DIALOG must be set, but not both.
#define FDS_CENTER 0x001 // Center within owner wnd
#define FDS_CUSTOM 0x002 // Use custom user template: NOT USED HERE
#define FDS_FILTERUNION 0x004 // Use union of filters: NOT USED HERE
#define FDS_HELPBUTTON 0x008 // Display Help button
#define FDS_APPLYBUTTON 0x010 // Display Apply button
#define FDS_PRELOAD_VOLINFO 0x020 // Preload volume info for each drive for current default directory
#define FDS_MODELESS 0x040 // Make dialog modeless: DO NOT USE
#define FDS_INCLUDE_EAS 0x080 // Query extended attributes for list box
#define FDS_OPEN_DIALOG 0x100 // Select Open dialog
#define FDS_SAVEAS_DIALOG 0x200 // Select SaveAs dialog
#define FDS_MULTIPLESEL 0x400 // Enable multiple selection
#define FDS_ENABLEFILELB 0x800 // Enable File list box if this is FDS_SAVEAS_DIALOG
// OKButtonText: String to put in the OK button. If not supplied or NULL
// then defaults to OK.
// Return: Return a string that is the full file specification of the
// file selected, or NULL if no file was selected. If
// FDS_MULTIPLESEL was specified, then this function will return
// NULL if no file was selected, or an array of names selected.
FileDialog(MatchingFileSpec,Title,Flags,OKButtonText)
{
// There were a lot of optional inputs, and so set defaults
_ParmCount = va_arg();
_MatchingFileSpec = ( _ParmCount < 1 || NULL == MatchingFileSpec )
? "*"
: MatchingFileSpec ;
_Title = ( _ParmCount < 2 ) ? NULL : Title;
_Flags = ( _ParmCount < 3 || 0 == Flags ) ? FDS_OPEN_DIALOG | FDS_CENTER : Flags;
_OKButtonText = ( _ParmCount < 4 ) ? NULL : OKButtonText ;
// The file dialog structure is very large, but most of its fields are
// not used. Set all to zero except for the few we need.
#define FILEDLG_SIZE 328
BLObSize(FileDlg,FILEDLG_SIZE);
memset(FileDlg,0,FILEDLG_SIZE);
BLObPut(FileDlg,0,FILEDLG_SIZE,UWORD32);
// Set users flags
#define FD_FLAG_OFFSET 4
BLObPut(FileDlg,FD_FLAG_OFFSET,_Flags,UWORD32);
// set title and button
#define FD_TITLE_OFFSET 20
#define FD_BUTTON_OFFSET 24
if ( NULL != _Title ) {
// must give PM pointer to this title
PMpoke(_PMtitle = PMalloc(1+strlen(_Title)),_Title,1+strlen(_Title));
BLObPut(FileDlg,FD_TITLE_OFFSET,_PMtitle,UWORD32);
}
if ( NULL != _OKButtonText ) {
// must give PM pointer to this button text
PMpoke(_PMbutton = PMalloc(1+strlen(_OKButtonText)),_OKButtonText,1+strlen(_OKButtonText));
BLObPut(FileDlg,FD_BUTTON_OFFSET,_PMbutton,UWORD32);
}
// set initial search spec name
#define FD_FULLNAME_OFFSET 52
#define FD_FULLNAME_SIZE 260
BLObPut(FileDlg,FD_FULLNAME_OFFSET,_MatchingFileSpec,1+strlen(_MatchingFileSpec));
// Call the dialog function
#define ORD_WINFILEDLG 4
#define HWND_DESKTOP 1
#define FD_FILECOUNT_OFFSET 316
#define FD_RETURNCODE_OFFSET 12
#define DID_OK 1
_FileCount = ( PMDynamicLink("PMCTLS",ORD_WINFILEDLG,BIT32,CDECL,
HWND_DESKTOP,Info().WinHandle,FileDlg)
&& DID_OK == BLObGet(FileDlg,FD_RETURNCODE_OFFSET,UWORD32) )
? BLObGet(FileDlg,FD_FILECOUNT_OFFSET,UWORD32) : 0 ;
// don't need title and button pointers anymore
if ( NULL != _Title ) PMfree(_PMtitle);
if ( NULL != _OKButtonText ) PMfree(_PMbutton);
if ( 0 == _FileCount ) {
_ret = NULL; // No files found
} else if ( _Flags & FDS_MULTIPLESEL ) {
#define FD_FILELIST_OFFSET 312
_flist = BLObGet(FileDlg,FD_FILELIST_OFFSET,UWORD32);
if ( NULL == _flist ) {
_len = strlen(BLObGet(FileDlg,FD_FULLNAME_OFFSET,FD_FULLNAME_SIZE));
_ret[0] = BLObGet( FileDlg, FD_FULLNAME_OFFSET, 1 + _len );
} else {
for ( _i = 0; _i < _FileCount; _i++ ) {
_name = PMpeek(_flist + _i*4,UWORD32);
_len = strlen(PMpeek(_name,FD_FULLNAME_OFFSET));
_ret[_i] = PMpeek( _name, 1 + _len );
}
// finally, must free list of files
#define ORD_WINFREEFILEDLGLIST 6
PMDynamicLink("PMCTLS",ORD_WINFREEFILEDLGLIST,BIT32,CDECL,_flist);
}
} else {
// single response in FULLNAME
_len = strlen(BLObGet(FileDlg,FD_FULLNAME_OFFSET,FD_FULLNAME_SIZE));
_ret = BLObGet( FileDlg, FD_FULLNAME_OFFSET, 1 + _len );
}
return _ret;
}
/************** Routines used by above code ********************/
PMalloc(size)
{
#define ORD_DOS32ALLOCMEM 299
#define PAG_COMMIT 0x10
#define PAG_READ 0x1
#define PAG_WRITE 0x2
_FileCount = PMDynamicLink("DOSCALLS",ORD_DOS32ALLOCMEM,BIT32,CDECL,
_PMptr,size,PAG_COMMIT | PAG_READ | PAG_WRITE);
return(_PMptr);
}
PMfree(ptr)
{
#define ORD_DOS32FREEMEM 304
PMDynamicLink("DOSCALLS",ORD_DOS32FREEMEM,BIT32,CDECL,ptr);
}