Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29251 Discussions

HELP - Windows VISTA/Windows 7 NEW Common Dialog Interface

portoon
Beginner
1,397 Views

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.

0 Kudos
7 Replies
Paul_Curtis
Valued Contributor I
1,397 Views
The following works just fine on all versions of Windows, including Vista and Win7:

[bash]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
[/bash]
0 Kudos
rase
New Contributor I
1,397 Views
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.
0 Kudos
Paul_Curtis
Valued Contributor I
1,397 Views
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.
0 Kudos
Steven_L_Intel1
Employee
1,397 Views
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.
0 Kudos
portoon
Beginner
1,397 Views

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...?

0 Kudos
Morten_Hartvig_H_
1,397 Views
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
0 Kudos
Steven_L_Intel1
Employee
1,397 Views
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.
0 Kudos
Reply