/* * getOpenFName - let the user select a file name for an open operation * fname must point to a buffer of length at least _MAX_PATH * also sets the type of file (bitmap, icon, cursor). */ static BOOL getOpenFName( char *fname ) { static OPENFILENAME of; char szFileTitle[_MAX_PATH]; int rc; long of_size; of_size = sizeof(OPENFILENAME); #if defined (__NT__) && (WINVER >= 0x0500) && (_WIN32_WINNT >= 0x0500) { OSVERSIONINFO os_info; os_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx( &os_info ); if( os_info.dwMajorVersion < 5 ) { of_size = OPENFILENAME_SIZE_VERSION_400; /* WIN32 major version < 5 detected */ /* See OPENFILENAME doc on www.msdn.com */ /* Added as future proofing... */ } } #endif fname[ 0 ] = 0; memset( &of, 0, of_size ); of.lStructSize = of_size; of.hwndOwner = HMainWindow; of.lpstrFilter = (LPSTR)IEImageFilter; of.lpstrDefExt = "*.*"; of.nFilterIndex = (long)imgType; of.lpstrFile = fname; of.nMaxFile = _MAX_PATH; of.lpstrFileTitle = szFileTitle; of.nMaxFileTitle = sizeof(szFileTitle); of.lpstrTitle = IEOpenImageTitle; of.lpstrInitialDir = initialDir; #if !defined (__NT__) /* Important! Do not use hook in WIN32, you will not get the nice dialog! */ of.lpfnHook = (LPVOID) MakeProcInstance( (LPVOID) OpenHook, Instance ); of.Flags = OFN_ENABLEHOOK; #endif of.Flags |= OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; rc = GetOpenFileName( &of ); #ifndef __NT__ FreeProcInstance( (LPVOID) of.lpfnHook ); #endif if( rc ) { imgType = getImageTypeFromFilename(fname); return( TRUE ); } else { return( FALSE ); } } /* getOpenFName */
/* * getOpenFName - let the user select a file name for an open operation * - fname must point to a buffer of length at least _MAX_PATH * - also set the type of file (bitmap, icon, cursor) */ static BOOL getOpenFName( char *fname ) { static OPENFILENAME of; char szFileTitle[_MAX_PATH]; int rc; long of_size; #if defined( __NT__ ) && (WINVER >= 0x0500) && (_WIN32_WINNT >= 0x0500) OSVERSIONINFO os_info; #endif of_size = sizeof( OPENFILENAME ); #if defined( __NT__ ) && (WINVER >= 0x0500) && (_WIN32_WINNT >= 0x0500) os_info.dwOSVersionInfoSize = sizeof( OSVERSIONINFO ); GetVersionEx( &os_info ); if( os_info.dwMajorVersion < 5 ) { /* Set the appropriate structure size to make this work on Windows 95. */ of_size = OPENFILENAME_SIZE_VERSION_400; } #endif fname[0] = '\0'; memset( &of, 0, of_size ); of.lStructSize = of_size; of.hwndOwner = HMainWindow; of.lpstrFilter = (LPSTR)IEImageFilter; of.lpstrDefExt = "*.*"; of.nFilterIndex = (long)imgType; of.lpstrFile = fname; of.nMaxFile = _MAX_PATH; of.lpstrFileTitle = szFileTitle; of.nMaxFileTitle = sizeof( szFileTitle ); of.lpstrTitle = IEOpenImageTitle; of.lpstrInitialDir = initialDir; #if !defined( __NT__ ) /* Important! Do not use hook in Win32, you will not get the nice dialog! */ of.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance( (FARPROC)OpenHook, Instance ); of.Flags = OFN_ENABLEHOOK; #endif of.Flags |= OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; rc = GetOpenFileName( &of ); #ifndef __NT__ FreeProcInstance( (FARPROC)of.lpfnHook ); #endif if( rc ) { imgType = getImageTypeFromFilename( fname ); return( TRUE ); } else { return( FALSE ); } } /* getOpenFName */
/* * OpenImage - get the filename of the file to open * - depending on the extension, set the type (.ico, .bmp, .cur) and call the * appropriate function to open it */ int OpenImage( HANDLE hDrop ) { char fname[_MAX_PATH]; int rv = FALSE; if( NULL == hDrop ) { /* * Not doing a drag-drop */ if( !getOpenFName( fname ) ) { if( CommDlgExtendedError() == FNERR_INVALIDFILENAME ) { WImgEditError( WIE_ERR_BAD_FILENAME, fname ); return( FALSE ); } return( FALSE ); } rv = reallyOpenImage( fname ); } else { /* * hDrop is only ever !NULL when we're dealing with a WM_DROPFILES * message, and that only happens with __NT__ */ #ifdef __NT__ int nFiles = DragQueryFile( hDrop, 0xFFFFFFFF, NULL, 0 ); int i; for( i = 0, rv = TRUE; rv && i < nFiles; i++ ) { DragQueryFile( hDrop, i, fname, _MAX_PATH - 1 ); imgType = getImageTypeFromFilename( fname ); rv = reallyOpenImage( fname ); } #endif } if( rv ) { SetupMenuAfterOpen(); } return( rv ); } /* OpenImage */