News:

Function Finder  Find all the functions within source code files

Main Menu

LoadDialog Replacement (Windows File Request)

Started by kevin, June 10, 2014, 08:24:18 AM

Previous topic - Next topic

kevin

   LoadDialog Replacement (Windows File Request)

      This example calls the windows open file dialog.   It's a replacement (of sort) for the PBdialogs library.  

      To request a file, call the LoadDialog() function.  The function has three main parameters,   Title$, PathAndFilename$ and Filter$

     Title$ = the title message that should appear across the top of this dialog

     PathAndFilename$ = (OPTIONAL) This can either be a Filename, or a filename with path$.  When the path is included, the dialog function will be passed this as the start up path for the dialog.    So you can prompt where the user starts searching for their file

     Filter$ = (OPTIONAL) THis defaults to all files, but you can set it to limit what file types (by extension) the user can choose between.  


 

PlayBASIC Code: [Select]
      cls 255

print LoadDialog("Load File","C:/PlayBASIC.exe")

Sync
waitkey

end





Type tOpenFileName
; DWORD lStructSize;
lStructSize;

; HWND hwndOwner;
hwndOwner

; HINSTANCE hInstance;
hInstance;

; LPCTSTR lpstrFilter;
lpstrFilter


; LPTSTR lpstrCustomFilter;
lpstrCustomFilter


; DWORD nMaxCustFilter;
nMaxCustFilter;

; DWORD nFilterIndex;
nFilterIndex;

; LPTSTR lpstrFile;
lpstrFile;

; DWORD nMaxFile;
nMaxFile;

; LPTSTR lpstrFileTitle;
lpstrFileTitle;


; DWORD nMaxFileTitle;
nMaxFileTitle;

; LPCTSTR lpstrInitialDir;
lpstrInitialDir;

; LPCTSTR lpstrTitle;
lpstrTitle;



; DWORD Flags;
Flags;

; WORD nFileOffset;
nFileOffset as word

; WORD nFileExtension;
nFileExtension as word

; LPCTSTR lpstrDefExt;
lpstrDefExt

; DWORD lCustData;
lCustData;

; LPOFNHOOKPROC lpfnHook;
lpfnHook;


; LPCTSTR lpTemplateName;
lpTemplateName;

endtype



constant OFN_READONLY = 0x00000001
constant OFN_OVERWRITEPROMPT = 0x00000002
constant OFN_HIDEREADONLY = 0x00000004
constant OFN_NOCHANGEDIR = 0x00000008
constant OFN_SHOWHELP = 0x00000010
constant OFN_ENABLEHOOK = 0x00000020
constant OFN_ENABLETEMPLATE = 0x00000040
constant OFN_ENABLETEMPLATEHANDLE = 0x00000080
constant OFN_NOVALIDATE = 0x00000100
constant OFN_ALLOWMULTISELECT = 0x00000200
constant OFN_EXTENSIONDIFFERENT = 0x00000400
constant OFN_PATHMUSTEXIST = 0x00000800
constant OFN_FILEMUSTEXIST = 0x00001000
constant OFN_CREATEPROMPT = 0x00002000
constant OFN_SHAREAWARE = 0x00004000
constant OFN_NOREADONLYRETURN = 0x00008000
constant OFN_NOTESTFILECREATE = 0x00010000
constant OFN_NONETWORKBUTTON = 0x00020000
constant OFN_NOLONGNAMES = 0x00040000 // force no long names for 4.x modules

constant OFN_EXPLORER = 0x00080000 // new look commdlg
constant OFN_NODEREFERENCELINKS = 0x00100000
constant OFN_LONGNAMES = 0x00200000 // force long names for 3.x modules
constant OFN_ENABLEINCLUDENOTIFY = 0x00400000 // send include message to callback
constant OFN_ENABLESIZING = 0x00800000




linkdll "comdlg32.dll"
GetOpenFileName(OFN_Structure_Ptr) alias "GetOpenFileNameA" as integer
EndLinkDll



Function LoadDialog(Title$,PathAndFilename$="",Filter$ = "(All Files | *.*)")

Dim OFN as tOpenFileName Pointer
OFN = new tOpenFileName
if Int(OFN)

OFN.lStructSize = sizeof(tOpenFileName)

// Strip the Filename from the what could be an absolute path/with filename$
Filename$=trim$(getfilename$(pathAndFilename$),"\/")

// path /oflder the dialog should open in (if none defaults to current dir$())
Path$=getfoldername$(pathAndFilename$)

// get the path$ exists, if it doesn't set to the currentdir$
if len(path$)
if folderexist(Path$)=false
path$=currentdir$()
endif
endif

OFN.lpstrInitialDir=_MakeDialogString(Path$)

OFN.lpstrFile =_MakeDialogString(Filename$)
OFN.nMaxFile =1024

OFN.hwndOwner =GetScreenHandle()


Login required to view complete source code



  Related Articles:

      Windows File Dialogs Library (login required)