HELP - Windows VISTA/Windows 7 NEW Common Dialog Interface

HELP - Windows VISTA/Windows 7 NEW Common Dialog Interface

I have a problem for GetOpenFileName/GetSaveFileName dialog box.

It works fine on Windows 2000/Windows XP but not on Windows VISTA/Windows 7.

So, I would like to change that interfaces to IFileDialog/IFileOpenDialog/IFileSaveDialog using WIN32 API.

The problem is that I have no idea about it.

There are some examples for MS VC++, VBA, but NOT Visual FORTRAN (WIN32 API).

Is there any one who knew about that one?

Thanks in advance.

8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

The following works just fine on all versions of Windows, including Vista and Win7:

LOGICAL FUNCTION CmnDlgOpenFile (hwndParent, filter, filename)
    USE charfunc, ONLY: NullTerminateString
    IMPLICIT NONE
    INTEGER(HANDLE), INTENT(IN)            :: hwndParent
    CHARACTER(LEN=*), INTENT(IN)           :: filter
    CHARACTER(LEN=*), INTENT(INOUT)        :: filename

    TYPE(T_OPENFILENAME)                   :: ofn
    
    CALL NullTerminateString(filename)
    
    !   ofn structure component list increased 
    !   to emulate IVF sample code GETOPENFILENAME.F90;
    !   omission of the extra components caused an
    !   access violation with the v11.0.074 compiler
    
    ofn%lStructSize       = SIZEOF(ofn)
    ofn%hwndOwner         = hwndParent 
    ofn%hInstance         = ghInstance
    ofn%lpstrFile         = LOC(filename)
    ofn%nMaxFile          = LEN(filename)
    ofn%lpstrFilter       = LOC(filter)
    ofn%nFilterIndex      = 1
    ofn%Flags             = IOR(OFN_HIDEREADONLY,   &
                             IOR(OFN_PATHMUSTEXIST, &
                                 OFN_FILEMUSTEXIST) )
    ofn%lpstrCustomFilter = NULL
    ofn%nMaxCustFilter    = 0
    ofn%nMaxFileTitle     = 0
    ofn%lpstrInitialDir   = NULL  ! Use Windows default directory
    ofn%lpstrTitle        = loc(""C)
    ofn%lpstrDefExt       = loc(""C)
    ofn%lpfnHook          = NULL
    ofn%lpTemplateName    = NULL

    CmnDlgOpenFile = GetOpenFileName(ofn)

END FUNCTION CmnDlgOpenFile

Could you be so kind to tell us where we can find more about the (new?) library charfunc and the included functions, for example TeminateNullString? I could not find the functions via Help.

Charfunc is a private library of string manipulation functions, similar to one posted here recently.

NullTerminateString() does exactly what the name says, ie adds a null byte beyond the last non-null character in the string, so that the string will be properly formatted for use by Win32 API functions.

You could replace the call to NullTerminateString with:

filename = TRIM(filename) // CHAR(0)

Of course, this (and the routine) require that Filename be a variable (and not a constant) and that it be long enough to contain the trailing NUL.

I'd be more comfortable with declaring a local variable that gets the nul-terminated string rather than modifying the argument.

Steve - Intel Developer Support

Thanks for reply.

I just disabled visual themes &desktop composition only, which is in the compatibility options.

OOPS, it works fine...!

Is there anyone, who can explain more about this case...?

I have been througth the other threads on this matter with stack problems and the inability for some users to be able to open and save files with GetOpenFileName/GetSaveFileName. It has not given answers to my similar problem with these functions on W7. I would like to try the recommended newer API functions IFileDialog/IFileOpenDialog/IFileSaveDialog but I lack a Intel Fortran sample. Please help ... thanks!

Best,
Morten

GetOpenFileName and GetSaveFileName work fine on Windows 7 as long as you call them correctly. The "newer API functions" you refer to are not callable APIs but rather COM methods. While you could get at these through the Fortran Module Wizard, it is probably not worth the trouble.

Steve - Intel Developer Support

Leave a Comment

Please sign in to add a comment. Not a member? Join today