commondialog文件夾
發布時間: 2023-05-28 21:04:11
⑴ VB commondialog如何才能選擇一個文件夾,返回其路徑讓我記錄下來
commondialog 似乎做不到這一點,可以調用API實現。
OptionExplicit
"shell32"(lpbiAsBrowseInfo)AsLong
"shell32"(ByValpidListAsLong,ByVallpBufferAsString)AsLong
"ole32.dll"(ByValhMemAsLong)
"kernel32"Alias"lstrcatA"(ByVallpString1AsString,ByVallpString2AsString)AsLong
PrivateTypeBrowseInfo
hWndOwnerAsLong
pIDLRootAsLong
pszDisplayName脊激AsLong
lpszTitleAsLong
ulFlagsAsLong
lpfnCallbackAsLong
lParamAsLong
iImageAsLong
EndType
PrivateConstBIF_RETURNONLYFSDIRS=1
Private枯鄭ConstMAX_PATH=260
'打開Windows的選擇目錄對話框
'hwnd為窗口句柄(通常設為Me.hwnd),Prompt為指示字元串
FunctionShowFolderSelection(ByValhwndAsLong,ByValPromptAsString)AsString
DimiNullAsInteger
DimlpIDListAsLong
DimlResultAsLong
DimsPathAsString
DimudtBIAsBrowseInfo
WithudtBI
.hWndOwner=hwnd
.lpszTitle=lstrcat(Prompt,"")
.ulFlags=BIF_RETURNONLYFSDIRS
EndWith
lpIDList=SHBrowseForFolder(udtBI)
IflpIDListThen
sPath=String$(MAX_PATH,0)
lResult=SHGetPathFromIDList(lpIDList,sPath)
CoTaskMemFreelpIDList
iNull=InStr(sPath,vbNullChar)
IfiNull櫻敗襪ThensPath=Left$(sPath,iNull-1)
EndIf
ShowFolderSelection=sPath
EndFunction
PrivateSubCommand1_Click()
ShowFolderSelectionMe.hwnd,"選擇目錄:"
EndSub
⑵ vb commondialog 路徑
設置 commondialog1.InitDir="你的路徑",按照你所歲做啟說的乎如,設置為commondialog1.InitDir=app.path & 「\你的文件夾1名稱」
commondialog2.InitDir=app.path & 「\你的胡陸文件夾2名稱」
熱點內容