Пример #1
0
/*
 * GetSaveFName - let the user select a file name for a save operation
 *                fname must point to a buffer of length at least _MAX_PATH
 */
BOOL GetSaveFName( HWND mainhwnd, char *fname )
{
    static char         filterList[] = "File (*.*)" \
                                       "\0" \
                                       "*.*" \
                                       "\0\0";
    OPENFILENAME        of;
    int                 rc;

    fname[0] = 0;
    memset( &of, 0, sizeof( OPENFILENAME ) );
    of.lStructSize = sizeof( OPENFILENAME );
    of.hwndOwner = mainhwnd;
    of.lpstrFilter = (LPSTR)filterList;
    of.lpstrDefExt = "";
    of.nFilterIndex = 1L;
    of.lpstrFile = fname;
    of.nMaxFile = _MAX_PATH;
    of.lpstrTitle = NULL;
    of.Flags = OFN_HIDEREADONLY;
#ifndef NOUSE3D
    of.Flags |= OFN_ENABLEHOOK;
    of.lpfnHook = (LPOFNHOOKPROC)MakeOpenFileHookProcInstance( LBSaveHook, GET_HINSTANCE( mainhwnd ) );
#endif
    rc = GetSaveFileName( &of );
#ifndef NOUSE3D
    FreeProcInstance( (FARPROC)of.lpfnHook );
#endif
    return( rc );

} /* GetSaveFName */
Пример #2
0
/*
 * SelectFileOpen - use common dialog file open to pick a file to edit
 */
vi_rc SelectFileOpen( const char *dir, char **result, const char *mask, bool want_all_dirs )
{
    OPENFILENAME        of;
    bool                rc;
    static long         filemask = 1;
    bool                is_chicago = false;

#if defined( __NT__ ) && !defined( _WIN64 )
    /* added to get around chicago crashing in the fileopen dlg */
    /* -------------------------------------------------------- */
    if( LOBYTE( LOWORD( GetVersion() ) ) >= 4 ) {
        is_chicago = true;
    }
    /* -------------------------------------------------------- */
#endif

    mask = mask;
    want_all_dirs = want_all_dirs;
    *result[0] = '\0';
    memset( &of, 0, sizeof( OPENFILENAME ) );
    of.lStructSize = sizeof( OPENFILENAME );
    of.hwndOwner = root_window_id;
    of.lpstrFilter = (LPSTR)filterList;
    of.lpstrDefExt = NULL;
    of.nFilterIndex = filemask;
    of.lpstrFile = *result;
    of.nMaxFile = FILENAME_MAX;
    of.lpstrTitle = NULL;
    of.lpstrInitialDir = dir;
    if( is_chicago ) {
        of.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT | OFN_EXPLORER;
    } else {
        of.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT | OFN_ENABLEHOOK;
        of.lpfnHook = (LPOFNHOOKPROC)MakeOpenFileHookProcInstance( OpenHook, InstanceHandle );
    }
    rc = GetOpenFileName( &of ) != 0;
    filemask = of.nFilterIndex;
    if( !is_chicago ) {
        (void)FreeProcInstance( (FARPROC)of.lpfnHook );
    }
    if( !rc && CommDlgExtendedError() == FNERR_BUFFERTOOSMALL ) {
        if( !is_chicago ) {
            MemFree( (char*)(of.lpstrFile) );
            *result = FileNameList;
        }
#if 0
        MyBeep();
        Message1( "Please open files in smaller groups" );
#endif
    }
    UpdateCurrentDirectory();
    return( ERR_NO_ERR );

} /* SelectFileOpen */
Пример #3
0
/*
 * SelectFileSave - use common dialog file open to pickname to save under
 */
vi_rc SelectFileSave( char *result )
{
    OPENFILENAME        of;
    int                 doit;
    bool                is_chicago = false;

    assert( CurrentFile != NULL );

    strcpy( result, CurrentFile->name );
    memset( &of, 0, sizeof( OPENFILENAME ) );
    of.lStructSize = sizeof( OPENFILENAME );
    of.hwndOwner = root_window_id;
    of.lpstrFilter = (LPSTR) filterList;
    of.lpstrDefExt = NULL;
    of.nFilterIndex = 1L;
    of.lpstrFile = result;
    of.nMaxFile = FILENAME_MAX;
    of.lpstrTitle = NULL;
    of.lpstrInitialDir = CurrentFile->home;
#if defined( __NT__ ) && !defined( _WIN64 )
    if( LOBYTE( LOWORD( GetVersion() ) ) >= 4 )
        is_chicago = true;
#endif
    if( is_chicago ) {
        of.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOREADONLYRETURN | OFN_EXPLORER;
    } else {
        of.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOREADONLYRETURN | OFN_ENABLEHOOK;
        of.lpfnHook = (LPOFNHOOKPROC)MakeOpenFileHookProcInstance( OpenHook, InstanceHandle );
    }
    doit = GetSaveFileName( &of );
    if( !is_chicago ) {
        (void)FreeProcInstance( (FARPROC)of.lpfnHook );
    }
    if( doit != 0 ) {
        UpdateCurrentDirectory();
        return( ERR_NO_ERR );
    } else {
        return( ERR_SAVE_CANCELED );
    }

} /* SelectFileSave */
Пример #4
0
/*
 * getLogName - get a filename for the log and check if the file already exists
 */
static BOOL getLogName( char *buf, HWND hwnd )
{
    OPENFILENAME        of;
    int                 rc;
    static char         fname[LOG_MAX_FNAME];
    static char         filterList[] = "File (*.*)" \
                                       "\0" \
                                       "*.*" \
                                       "\0\0";

    strcpy( fname, LogCurInfo.config.name );
    memset( &of, 0, sizeof( OPENFILENAME ) );
    of.lStructSize = sizeof( OPENFILENAME );
    of.hwndOwner = hwnd;
    of.lpstrFilter = (LPSTR)filterList;
    of.lpstrDefExt = NULL;
    of.nFilterIndex = 1L;
    of.lpstrFile = fname;
    of.nMaxFile = LOG_MAX_FNAME;
    of.lpstrTitle = AllocRCString( LOG_CHOOSE_LOG_NAME );
    of.Flags = OFN_HIDEREADONLY;
#ifndef NOUSE3D
    of.Flags |= OFN_ENABLEHOOK;
    of.lpfnHook = (LPOFNHOOKPROC)MakeOpenFileHookProcInstance( LogSaveHook, LogCurInfo.instance );
#endif
    rc = GetSaveFileName( &of );
#ifndef NOUSE3D
    FreeProcInstance( (FARPROC)of.lpfnHook );
#endif
    FreeRCString( (char *)of.lpstrTitle );
    if( !rc ) {
        return( FALSE );
    }
    strcpy( buf, fname );
    return( TRUE );

} /* getLogName */
Пример #5
0
int GUIGetFileName( gui_window *wnd, open_file_name *ofn )
{
    OPENFILENAME        wofn;
    bool                issave;
    int                 rc;
    unsigned            drive;
#if defined(HAVE_DRIVES)
    unsigned            old_drive;
    unsigned            drives;
#endif

    LastPath = NULL;
    if( ofn->initial_dir != NULL && ofn->initial_dir[0] != '\0' && ofn->initial_dir[1] == ':' ) {
        drive = ofn->initial_dir[0];
        memmove( ofn->initial_dir, ofn->initial_dir+2, strlen( ofn->initial_dir+2 ) + 1 );
    } else {
        drive = 0;
    }

    memset( &wofn, 0 , sizeof( wofn ) );

    if( ofn->flags & OFN_ISSAVE ) {
        issave = true;
    } else {
        issave = false;
    }

    wofn.Flags = 0;
    if( hookFileDlg ) {
        wofn.Flags |= OFN_ENABLEHOOK;
    }
    if( !(ofn->flags & OFN_CHANGEDIR) ) {
        wofn.Flags |= OFN_NOCHANGEDIR;
    }

    if( ofn->flags & OFN_OVERWRITEPROMPT ) {
        wofn.Flags |= OFN_OVERWRITEPROMPT;
    }
    if( ofn->flags & OFN_HIDEREADONLY ) {
        wofn.Flags |= OFN_HIDEREADONLY;
    }
    if( ofn->flags & OFN_FILEMUSTEXIST ) {
        wofn.Flags |= OFN_FILEMUSTEXIST;
    }
    if( ofn->flags & OFN_PATHMUSTEXIST ) {
        wofn.Flags |= OFN_PATHMUSTEXIST;
    }
    if( ofn->flags & OFN_ALLOWMULTISELECT ) {
        wofn.Flags |= OFN_ALLOWMULTISELECT;
    }
    wofn.hwndOwner = GUIGetParentFrameHWND( wnd );
    wofn.hInstance = GUIMainHInst;
    wofn.lStructSize = sizeof( wofn );
    wofn.lpstrFilter = ofn->filter_list;
    wofn.nFilterIndex = ofn->filter_index;
    wofn.lpstrFile = ofn->file_name;
    wofn.nMaxFile = ofn->max_file_name;
    wofn.lpstrFileTitle = ofn->base_file_name;
    wofn.nMaxFileTitle = ofn->max_base_file_name;
    wofn.lpstrTitle = ofn->title;
    wofn.lpstrInitialDir = ofn->initial_dir;
    wofn.lpfnHook = (LPOFNHOOKPROC)NULL;
    if( hookFileDlg ) {
        wofn.lpfnHook = (LPOFNHOOKPROC)MakeOpenFileHookProcInstance( OpenHook, GUIMainHInst );
    }

#if defined( HAVE_DRIVES )
    if( drive ) {
        _dos_getdrive( &old_drive );
        _dos_setdrive( tolower( drive ) - 'a' + 1, &drives );
    }
#endif
    if( issave ) {
        rc = GetSaveFileName( &wofn );
    } else {
        rc = GetOpenFileName( &wofn );
    }

    if( hookFileDlg ) {
        (void)FreeProcInstance( (FARPROC)wofn.lpfnHook );
    }

    if( LastPath && ( !rc || !( ofn->flags & OFN_WANT_LAST_PATH ) ) ) {
        GUIMemFree( LastPath );
        LastPath = NULL;
    }
    ofn->last_path = LastPath;
#if defined( HAVE_DRIVES )
    if( drive ) {
        _dos_setdrive( old_drive, &drives );
    }
#endif
    if( rc ) {
        return( OFN_RC_FILE_SELECTED );
    }
    if( !CommDlgExtendedError() ) {
        return( OFN_RC_NO_FILE_SELECTED );
    }
    return( OFN_RC_FAILED_TO_INITIALIZE );
} /* _GUIGetFileName */