Kenny, Here is some sample code based on what is in the library.
#include <string.h>
#include <ctype.h>
#include <dir.h>
#include <stdio.h>
#include <windows.h>
#include <commdlg.h>
enum logical {false, true};
static logical get_file_name(HWND parent,char* title,char* ufileName,
int bufLen,char* filter,char* defPath,logical must_exist,logical saving)
{
logical l;
const int file_length = 500;
int mlen;
static char szDialogDirName[300];
char fileName[file_length];
OPENFILENAME ofn;
char szDirName[300];
char szFilter[]=
'All files (*.*)\\0*.*\\0'
'\\0';
if (fileName==NULL || bufLen<1) return false;
if(bufLen > file_length) mlen = file_length;
else mlen=bufLen;
strncpy(fileName,ufileName,mlen);
*(fileName+mlen-1)=0;
getcwd(szDirName,300);
strcpy(szDialogDirName,defPath);
if (filter==NULL) filter=szFilter;
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = parent;
ofn.hInstance = windows_instance();
ofn.lpstrFilter = filter;
ofn.lpstrCustomFilter = NULL;
ofn.nMaxCustFilter = 0L;
ofn.nFilterIndex = 1L;
ofn.lpstrFile = fileName;
ofn.nMaxFile = mlen;
ofn.lpstrInitialDir = szDialogDirName;
ofn.lpstrFileTitle = NULL;
ofn.lpstrTitle = title;
if(title) ofn.nMaxFileTitle=strlen(title)+1;
else ofn.nMaxFileTitle=0;
if(must_exist) ofn.Flags=OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
else ofn.Flags=OFN_HIDEREADONLY;
ofn.nFileOffset = 0;
ofn.nFileExtension = 0;
ofn.lpstrDefExt = NULL;
ofn.lCustData = NULL;
ofn.lpfnHook = NULL;
ofn.lpTemplateName = NULL;
if(saving) l = logical(GetSaveFileName(&ofn));
else l = logical(GetOpenFileName(&ofn));
if(l) strncpy(ufileName,fileName,mlen);
return l;
}
extern 'C' void __get_filtered_file(char* z_title,char* file,char* z_path, char** filter_names, char** filter_specs, int must_exist)
{
char z_file[MAX_PATH+1];
char file_filter[512];
HWND parent=NULL;
char* p=file_filter;
int i=0;
while(filter_names && filter_names[i])
{
strcpy(p,filter_names[i]);
strcat(p,' (');
strcat(p,filter_specs[i]);
strcat(p,')');
p=strend(p)+1;
p=stpcpy(p,filter_specs[i])+1;
i++;
}
*p=0;
strcpy(z_file,file);
logical found=get_file_name(parent, z_title, z_file, MAX_PATH+1, file_filter, z_path, logical(must_exist), logical(!must_exist));
if(found) strcpy(file,z_file);
else file[0]=0;
}
int main()
{
char file[MAX_PATH];
char* filter_names[] = {'Bitmap files', 'All files', NULL};
char* filter_specs[] = {'*.bmp','*.*',NULL};
*file = 0;
__get_filtered_file('Open File', file, 'C:\\techsupport', filter_names, filter_specs, TRUE);
printf('%s\\n', file);
return 0;
}