The ImgOpenDialog, ImgXWriteImage and ImgXWriteDIB functions all include support for enhanced File Open and File Save dialogs. The Open File dialog displayed by ImgOpenDialog includes options for displaying the image statistics and a preview thumbnail. The ImgXWriteImage and ImgXWriteDIB functions include an enhanced dialog that allows the user to optionally specify format specific information when saving the image.
You may also use the Common Dialog functions directly and bypass the ImageMan Common Dialogs. To help you work with these functions, and to just generally promote standards, the ImgGetExt functions returns a string which you can assign directly to lpstrFilter in the OPENFILENAME structure passed to the GetOpenFileName function, making it easy for your app to create a load image dialog box. The following example illustrates using the GetOpenFileName dialog with ImageMan:
HANDLE NEAR PASCAL GetImage ( HANDLE hWnd )
{
OPENFILENAME ofn ;
HANDLE hImage ;
char szFile[256], szFileTitle[256] ;
szFile[0] = '\0';
hImage = NULL ;
ofn.lStructSize = sizeof(OPENFILENAME) ;
ofn.hwndOwner = hWnd ;
ofn.lpstrFilter = ImgGetExt () ;
ofn.lpstrCustomFilter = (LPSTR)NULL ;
ofn.nMaxCustFilter = 0 ;
ofn.nFilterIndex = 1 ;
ofn.lpstrFile = szFile ;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFileTitle = szFileTitle ;
ofn.nMaxFileTitle = sizeof(szFileTitle) ;
ofn.lpstrInitialDir = lpDefPath ;
ofn.lpstrTitle = "Open Image" ;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST ;
ofn.nFileOffset = 0 ;
ofn.nFileExtension = 0;
ofn.lpstrDefExt = NULL;
if( GetOpenFileName( &ofn ) ) {
hImage = ImgOpenSolo( ofn.lpstrFile, NULL );
if ( ! hImage )
ImgErrBox( hWnd ) ;
}
// get rid of ext string
GlobalFreePtr ( ofn.lpstrFilter );
return hImage;
}
Important
Notice that your application is responsible for disposing of the string returned from ImgGetExt. The GlobalFreePtr() macro used in the sample code is defined in the windowsx.h file.
© 1995-2004 Data Techniques, Inc. All rights reserved.