⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ieopen.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
{
    FILE                *fp;
    an_img_file         *cursorfile;
    an_img              *cursor;

    fp = fopen( fname, "rb" );
    if (!fp) {
        WImgEditError( WIE_ERR_FILE_NOT_OPENED, fname );
        return( FALSE );
    }

    cursorfile = ImageOpen( fp );
    if (!cursorfile) {
        fclose( fp );
        WImgEditError( WIE_ERR_BAD_CURSOR_FILE, fname );
        return( FALSE );
    }
    cursor = ImgResourceToImg( fp, cursorfile, 0 );
    fclose( fp );

    return( DoReadCursor( fname, cursorfile, cursor, NULL, NULL ) );
} /* readInCursorFile */

/*
 * readCursorFromData - Read the cursor data and set up structures.
 */
BOOL readCursorFromData( void *data, char *fname, WRInfo *info,
                         WResLangNode *lnode )
{
    unsigned            pos;
    an_img_file         *cursorfile;
    an_img              *cursor;
    BOOL                ret;

    pos = 0;
    cursorfile = ImageOpenData( (BYTE *)data, &pos );
    if (!cursorfile) {
        WImgEditError( WIE_ERR_BAD_CURSOR_DATA, fname );
        return( FALSE );
    }
    cursor = ImgResourceToImgData( (BYTE *)data, &pos, cursorfile, 0 );

    ret = DoReadCursor( fname, cursorfile, cursor, info, lnode );

    if( ret ) {
        SetupMenuAfterOpen();
    }

    return( ret );
} /* readCursorFromData */

/*
 * OpenHook - hook used called by common dialog - for 3-d controls
 */
BOOL CALLBACK OpenHook( HWND hwnd, int msg, UINT wparam, LONG lparam )
{
    wparam = wparam;
    lparam = lparam;
    hwnd = hwnd;
    switch( msg ) {
    case WM_INITDIALOG:
        // We must call this to subclass the directory listbox even
        // if the app calls Ctl3dAutoSubclass (commdlg bug)
#if defined (__NT__)
        // Only do it if NOT new shell.
        if ( LOBYTE(LOWORD(GetVersion())) < 4 )
#endif
            IECtl3dSubclassDlg( hwnd, CTL3D_ALL );
        return( TRUE );
    }
    return( FALSE );

} /* OpenHook */

static int getImageTypeFromFilename(char *fname)
{
    char                ext[ _MAX_EXT ];
    char                drive[ _MAX_DRIVE ];
    char                path[ _MAX_PATH ];

    _splitpath( fname, drive, path, NULL, ext );
    strcpy( initialDir, drive );
    strcat( initialDir, path );
    initialDir[ strlen(initialDir)-1 ] = '\0';

    if( !stricmp(ext, ".bmp") ) {
        return BITMAP_IMG;
    } else if( !stricmp(ext, ".ico") ) {
        return ICON_IMG;
    } else if( !stricmp(ext, ".cur") ) {
        return CURSOR_IMG;
    } else if( !stricmp(ext, ".res") || !stricmp(ext, ".exe") ||
               !stricmp(ext, ".dll") ) {
        return RESOURCE_IMG;
    } else {
        return UNDEF_IMG;
    }
}
/*
 * 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 */

static BOOL readInResourceFile( char *fullname )
{
    BYTE                *data;
    uint_32             dsize;
    WRInfo              *info;
    WRSelectImageInfo   *sii;
    WPI_PROC            cb;
    BOOL                ok;

    info = NULL;
    sii = NULL;
    data = NULL;
    ok = ( fullname != NULL );

    if( ok ) {
        info = WRLoadResource( fullname, WR_DONT_KNOW );
        ok = ( info != NULL );
    }

    if( ok ) {
        cb = _wpi_makeprocinstance( (WPI_PROC)IEHelpCallBack, Instance );
        sii = WRSelectImage( HMainWindow, info, cb );
        _wpi_freeprocinstance( cb );
        ok = ( sii && sii->lnode );
    }

    if( ok ) {
        if( sii->type == (uint_16)RT_BITMAP ) {
            imgType = BITMAP_IMG;
            data = WRCopyResData( info, sii->lnode );
            dsize = sii->lnode->Info.Length;
            ok = ( data != NULL );
            if( ok ) {
                ok = WRAddBitmapFileHeader( &data, &dsize );
            }
        } else if( sii->type == (uint_16)RT_GROUP_CURSOR ) {
            imgType = CURSOR_IMG;
            ok = WRCreateCursorData( info, sii->lnode, &data, &dsize );
        } else if( sii->type == (uint_16)RT_GROUP_ICON ) {
            imgType = ICON_IMG;
            ok = WRCreateIconData( info, sii->lnode, &data, &dsize );
        } else {
            imgType = UNDEF_IMG;
            ok = FALSE;
        }
    }

    if( ok ) {
        if( sii->type == (uint_16)RT_BITMAP ) {
            ok = readBitmapFromData( data, fullname, info, sii->lnode );
        } else if( sii->type == (uint_16)RT_GROUP_CURSOR ) {
            ok = readCursorFromData( data, fullname, info, sii->lnode );
        } else if( sii->type == (uint_16)RT_GROUP_ICON ) {
            ok = readIconFromData( data, fullname, info, sii->lnode );
        }
    }

    if( sii ) {
        WRFreeSelectImageInfo( sii );
    }

    if( data != NULL ) {
        MemFree( data );
    }

    return( ok );
}

static int ReallyOpenImage(char *fname)
{
    char                filename[ _MAX_FNAME + _MAX_EXT ];
    
    switch( imgType ) {
    case BITMAP_IMG:
        if( !readInBitmapFile( fname ) ) {
            return( FALSE );
        }
        break;
    case ICON_IMG:
        if( !readInIconFile( fname ) ) {
            return( FALSE );
        }
        break;
    case CURSOR_IMG:
        if( !readInCursorFile( fname ) ) {
            return( FALSE );
        }
        break;
    case RESOURCE_IMG:
        if( !readInResourceFile( fname ) ) {
            return( FALSE );
        }
        break;
    default:
        GetFnameFromPath( fname, filename );
        WImgEditError( WIE_ERR_BAD_FILE_EXT, filename );
        imgType = BITMAP_IMG;
        return( FALSE );
        break;
    }

    return( imgType );
} /* ReallyOpenImage */

/*
 * 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),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 */
/*
 * getOpenPalName - let the user select a palette file name to load
 */
static BOOL getOpenPalName( 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)IEPaletteFilter;
    of.lpstrDefExt = "*.*";
    of.nFilterIndex = 0L;
    of.lpstrFile = fname;
    of.nMaxFile = _MAX_PATH;
    of.lpstrFileTitle = szFileTitle;
    of.nMaxFileTitle = sizeof(szFileTitle);
    of.lpstrTitle = IEOpenPaletteTitle;
    of.lpstrInitialDir = initialDir;
    of.Flags =  OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST |
                OFN_HIDEREADONLY;
#if !defined (__NT__)
    of.Flags |= OFN_ENABLEHOOK;
    of.lpfnHook = (LPVOID) MakeProcInstance( (LPVOID) OpenHook, Instance );
#endif
    rc = GetOpenFileName( &of );
    #ifndef __NT__
    FreeProcInstance( (LPVOID) of.lpfnHook );
    #endif
    return( rc );

} /* getOpenPalName */

/*
 * LoadColourPalette - loads a palette
 */
BOOL LoadColourPalette( void )
{
    char                fname[ _MAX_PATH ];
    char                filename[ _MAX_FNAME + _MAX_EXT ];
    a_pal_file          *pal_file;
    FILE                *fp;
    WORD                file_type;

    if (!getOpenPalName( &fname )) {
        if ( CommDlgExtendedError() == FNERR_INVALIDFILENAME ) {
            WImgEditError( WIE_ERR_BAD_FILENAME, fname );
            return( FALSE );
        }
        return( TRUE );
    }

    pal_file = MemAlloc( sizeof(a_pal_file) );
    fp = fopen( fname, "rb" );
    if (!fp) {
        WImgEditError( WIE_ERR_FILE_NOT_OPENED, fname );
        return( FALSE );
    }

    GetFnameFromPath( fname, filename );

    fseek( fp, 0L, SEEK_SET );
    fread( &file_type, sizeof( WORD ), 1, fp );
    if( file_type != PALETTE_FILE ) {
        WImgEditError( WIE_ERR_BAD_PALFILE, filename );
        fclose( fp );
        return( FALSE );
    }

    fseek( fp, 0L, SEEK_SET );
    fread( pal_file, sizeof( a_pal_file ), 1, fp );

    fclose( fp );
    SetNewPalette( pal_file );
    PrintHintTextByID( WIE_PALETTELOADEDFROM, filename );

    MemFree( pal_file );
    return(TRUE);
} /* LoadColourPalette */

/*
 * SetInitialOpenDir - sets the initial directory for the open filename
 */
void SetInitialOpenDir( char *new_dir )
{
    if (new_dir) {
        strcpy( initialDir, new_dir );
    } else {
        strcpy( initialDir, "" );
    }
} /* SetInitialOpenDir */

/*
 * GetInitOpenDir - gets the directory which we want to use as our initial one
 *              next time we run.
 */
char *GetInitOpenDir( void )
{
    return(initialDir);
} /* GetInitOpenDir */

/*
 * OpenFileOnStart - opens a file on program startup
 */
void OpenFileOnStart( char *fname )
{
    int         namelen;
    char        ext[ _MAX_EXT ];
    FILE        *fp;

    fp = fopen( fname, "r" );
    if( fp == NULL ) {
        if( OpenNewFiles ) {
            if( NewImage( UNDEF_IMG, fname ) ) {
                return;
            }
        }
        WImgEditError( WIE_ERR_STARTUP_FNO, fname );
        return;
    }
    fclose( fp );

    namelen = strlen( fname );
    strcpy( ext, &(fname[namelen-3]) );

    if( strcmpi(ext, "bmp") == 0 ) {
        if (!readInBitmapFile( fname )) {
            return;
        }
    } else if( strcmpi(ext, "ico") == 0 ) {
        if (!readInIconFile( fname )) {
            return;
        }
    } else if( strcmpi(ext, "cur") == 0 ) {
        if (!readInCursorFile( fname )) {
            return;
        }
    } else {
        return;
    }

    SetupMenuAfterOpen();

} /* OpenFileOnStart */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -