Good idea!
This my latest effort, with a cleaned-up header. I've included it in the latest Oxygen in examples/GUI/.
'no case sensitivity
% OFN_READONLY 0x00000001
% OFN_OVERWRITEPROMPT 0x00000002
% OFN_HIDEREADONLY 0x00000004
% OFN_NOCHANGEDIR 0x00000008
% OFN_SHOWHELP 0x00000010
% OFN_ENABLEHOOK 0x00000020
% OFN_ENABLETEMPLATE 0x00000040
% OFN_ENABLETEMPLATEHANDLE 0x00000080
% OFN_NOVALIDATE 0x00000100
% OFN_ALLOWMULTISELECT 0x00000200
% OFN_EXTENSIONDIFFERENT 0x00000400
% OFN_PATHMUSTEXIST 0x00000800
% OFN_FILEMUSTEXIST 0x00001000
% OFN_CREATEPROMPT 0x00002000
% OFN_SHAREAWARE 0x00004000
% OFN_NOREADONLYRETURN 0x00008000
% OFN_NOTESTFILECREATE 0x00010000
% OFN_NONETWORKBUTTON 0x00020000
% OFN_NOLONGNAMES 0x00040000 '// force no long names for 4.x modules
% OFN_EXPLORER 0x00080000 '// new look commdlg
% OFN_NODEREFERENCELINKS 0x00100000
% OFN_LONGNAMES 0x00200000 '// force long names for 3.x modules
% OFN_ENABLEINCLUDENOTIFY 0x00400000 '// send include message to callback
% OFN_ENABLESIZING 0x00800000
% OFN_DONTADDTORECENT 0x02000000
% OFN_FORCESHOWHIDDEN 0x10000000 '// Show All files including System and hidden files
type OPENFILENAMEA
DWORD lStructSize
SYS hwndOwner
SYS hInstance
CHAR* lpstrFilter
CHAR* lpstrCustomFilter
DWORD nMaxCustFilter
DWORD nFilterIndex
CHAR* lpstrFile
DWORD nMaxFile
CHAR* lpstrFileTitle
DWORD nMaxFileTitle
CHAR* lpstrInitialDir
CHAR* lpstrTitle
DWORD Flags
WORD nFileOffset
WORD nFileExtension
CHAR* lpstrDefExt
LONG lCustData
SYS lpfnHook
CHAR* lpTemplateName
end type
typedef OPENFILENAMEA OPENFILENAME
Declare GetModuleHandle lib "kernel32.dll" alias "GetModuleHandleA" (optional char*n) as sys
Declare GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (OPENFILENAME*opfn) As sys
Declare CommDlgExtendedError Lib "comdlg32.dll" () as dword
'FileDialog( $ iDir , $ filter ,$ title , % parent , flag )
Function FileDialog(string iDir, filter, Title, sys Hwnd, Flags) As String
'==================
def FileNameLen 256
OPENFILENAME ofn
char filename[FileNameLen]
int retval
ofn.lStructSize = sizeof(OPENFILENAME)
ofn.hwndOwner = hWnd
ofn.hInstance = GetModuleHandle
ofn.lpstrFilter = filter
ofn.lpstrCustomFilter = null
ofn.nMaxCustFilter = 0
ofn.nFilterIndex = 1
ofn.lpstrFile = FileName 'coupling to char buffer
ofn.nMaxFile = FileNameLen
ofn.lpstrFileTitle = null
ofn.nMaxFileTitle = 0
ofn.lpstrInitialDir = idir
ofn.lpstrTitle = title
ofn.Flags = flags
ofn.nFileOffset = 0
ofn.nFileExtension = 0
ofn.lpstrDefExt = null
ofn.lCustData = 0
ofn.lpfnHook = 0
ofn.lpTemplateName = null
sys retval = GetOpenFileName(ofn)
'
'http://msdn.microsoft.com/en-us/library/windows/desktop/ms646916(v=vs.85).aspx
'if retval=0 then print "Dialog Error " CommDlgExtendedError
return filename
'#recordof FileDialog
'
End Function
'dir="C:\cevp\projects\opcode\OxygenBasic\examples\GUI"
sys hwnd
string dir=""
string sep=chr(0)
string filter=
"all files"+sep+"*.*"+sep+
"text"+sep+"*.txt"+sep+
"basic"+sep+"*.bas;*.o2bas"+sep+
"include"+sep+"*.inc"+sep+
"header"+sep+"*.h"+sep+
sep
string title = "Test File Opening Dialog"
sys flags = OFN_EXPLORER or OFN_OVERWRITEPROMPT or OFN_HIDEREADONLY
string fi = FileDialog(dir,filter,title,hwnd,flags)
if fi then print fi