以下是引用csyx在2022-3-17 14:58:47的发言:
期待早日看到同样风格的取文件夹功能,vfp的GetDir函数样式跟吹版的GetFile实在不协调
只贴出新增加的代码,看看之前的贴出的代码自己分别加入 StructCalss.h 和 StructCalss.prg
头文件新增
程序代码:
** Browsing for directory.
#define BIF_RETURNONLYFSDIRS 0x0001 && For finding a folder to start document searching
#define BIF_DONTGOBELOWDOMAIN 0x0002 && For starting the Find Computer
#define BIF_STATUSTEXT 0x0004 && Top of the dialog has 2 lines of text for BROWSEINFO.lpszTitle and one line if
&& this flag is set. Passing the message BFFM_SETSTATUSTEXTA to the hwnd can set the
&& rest of the text. This is not used with BIF_USENEWUI and BROWSEINFO.lpszTitle gets
&& all three lines of text.
#define BIF_RETURNFSANCESTORS 0x0008
#define BIF_EDITBOX 0x0010 && Add an editbox to the dialog
#define BIF_VALIDATE 0x0020 && insist on valid result (or CANCEL)
#define BIF_NEWDIALOGSTYLE 0x0040 && Use the new dialog layout with the ability to resize
&& Caller needs to call OleInitialize() before using this API
#define BIF_USENEWUI (BIF_NEWDIALOGSTYLE + BIF_EDITBOX)
#define BIF_BROWSEINCLUDEURLS 0x0080 && Allow URLs to be displayed or entered. (Requires BIF_USENEWUI)
#define BIF_BROWSEFORCOMPUTER 0x1000 && Browsing for Computers.
#define BIF_BROWSEFORPRINTER 0x2000 && Browsing for Printers
#define BIF_BROWSEINCLUDEFILES 0x4000 && Browsing for Everything
#define BIF_SHAREABLE 0x8000 && sharable resources displayed (remote shares, requires BIF_USENEWUI)
新增结构类
程序代码:
DEFINE CLASS BROWSEINFOA AS STRUCT_CALSS
PROCEDURE init
DIMENSION this.aSTRUCT[8,4]
this.stInit(1, "hwndOwner", "N",4)
this.stInit(2, "pidlRoot", "N",4)
this.stInit(3, "pszDisplayName", "N",4)
this.stInit(4, "lpszTitle", "N",4)
this.stInit(5, "ulFlags", "N",4)
this.stInit(6, "lpfn", "N",4)
this.stInit(7, "lParam", "N",4)
this.stInit(8, "iImage", "N",4)
STRUCT_CALSS::init
ENDPROC
ENDDEFINE
新增API
程序代码:
DECLARE LONG CoTaskMemFree IN Ole32 LONG
DECLARE long ILCreateFromPath IN shell32 string@
DECLARE long SHBrowseForFolder IN shell32 long
DECLARE long SHGetPathFromIDList IN shell32 long, long
demo
程序代码:
**
** StructCalss_DirDialog.prg
**
#INCLUDE StructCalss.h
SET PROCEDURE TO StructCalss.prg ADDITIVE
LoadApi()
? myGetDir("C:\temp")
SET PROCEDURE TO
CLEAR ALL
RETURN
FUNCTION myGetDir(cDefDir)
LOCAL bi, pDir, cDir, pci, pit
pDir = apiMalloc(MAX_PATH)
cDefDir = STRCONV(ADDBS(cDefDir)+0h00, 5)
pci = ILCreateFromPath(@cDefDir)
bi = CREATEOBJECT("BROWSEINFOA")
bi.setValue("pidlRoot", pci)
bi.setValue("pszDisplayName", pDir)
bi.setValue("ulFlags", BIF_BROWSEINCLUDEFILES)
pit = SHBrowseForFolder(bi.pBuffer)
IF pit > 0
SHGetPathFromIDList(pit, pDir)
cDir = SYS(2600, pDir, apiStrlen(pDir))
CoTaskMemFree(pit)
ENDIF
CoTaskMemFree(pci)
apiFree(pDir)
RETURN cDir
ENDFUNC