! Example of calling the Win32 API routine GetOpenFileName
! This can be used from any application type, including Console
! Make sure that comdlg32.lib is included in the list of libraries
! to be searched.
!
! GetSaveFileName is very similar.
!
!program fileopen
subroutine SelectFile(lpstrInitialDir ,lpstrFilter, lpstrTitle, nFilterIndex, &
					lpstrDefExt, file_spec, status)
use dfwin
implicit none

character*(*) lpstrInitialDir ,lpstrFilter, lpstrTitle, lpstrDefExt
integer nFilterIndex
! Declare structure used to pass and receive attributes
!
type(T_OPENFILENAME) ofn

! Declare filter specification.  This is a concatenation of
! pairs of null-terminated strings.  The first string in each pair
! is the file type name, the second is a semicolon-separated list
! of file types for the given name.  The list ends with a trailing
! null-terminated empty string.
!
!character*(*) filter_spec != &
!  "Data Files"C//"*.dat"C// &
!  "Text Files"C//"*.txt"C//& !//""C 
!  "Fortran Files"C//"*.f90;*.f"//&
!  "All files"C//"*.*"C//""C 

! Declare string variable to return the file specification.
! Initialize with an initial filespec, if any - null string
! otherwise
!
character*max_path :: file_spec	! = ""C !512
integer status,ilen


ofn%lStructSize = SIZEOF(ofn)
ofn%hwndOwner = NULL  ! You may want to set these for
ofn%hInstance = NULL  ! non-console applications
ofn%lpstrFilter = loc(lpstrFilter)
ofn%lpstrCustomFilter = NULL
ofn%nMaxCustFilter = 0
ofn%nFilterIndex = nFilterIndex	!3 ! Specifies initial filter value
ofn%lpstrFile = loc(file_spec)
ofn%nMaxFile = sizeof(file_spec)
ofn%nMaxFileTitle = 0
ofn%lpstrInitialDir = loc(lpstrInitialDir) !NULL  ! Use Windows default directory/ Current dir.
ofn%lpstrTitle = loc(lpstrTitle)	!loc(""C)
ofn%Flags = OFN_PATHMUSTEXIST
ofn%lpstrDefExt = loc(lpstrDefExt)
ofn%lpfnHook = NULL
ofn%lpTemplateName = NULL

! Call GetOpenFileName and check status
! 
status = GetOpenFileName(ofn)

end subroutine SelectFile

 