vb6选择文件夹
Ⅰ VB2010中怎样打开文件夹
VB6不能直接选择文件夹,需要用到API,VB.NET就很简单了,FolderBrowserDialog控件就是用于选择文件夹的:
1234 <a
href="https://www..com/s?wd=Private&tn=44039180_cpr&fenlei=-bIi4WUvYETgN-"
target="_blank"
class="-highlight">Private</a> Sub Button1_Click(ByVal s<a
href="https://www..com/s?wd=end&tn=44039180_cpr&fenlei=-bIi4WUvYETgN-"
target="_blank"
class="-highlight">end</a>er As System.Object, ByVal e As System.EventArgs) Handles Button1.Click FolderBrowserDialog1.ShowDialog() MsgBox(FolderBrowserDialog1.SelectedPath) <a
href="https://www..com/s?wd=End&tn=44039180_cpr&fenlei=-bIi4WUvYETgN-"
target="_blank"
class="-highlight">End</a> Sub
Ⅱ 请教vb6中如何选择文件夹路径
'在主窗体中,加入以下代码
OptionExplicit
PrivateSubForm_Load()
Me.Caption=C_SelectPath(Me.hwnd,App.Path)'选择文件夹路径
EndSub
'========================================================================
'在模块中加入下面的代码
OptionExplicit
PrivatemSetPathAsString
PrivateTypeBrowseInfo
hWndOwnerAsLong
pIDLRootAsLong
pszDisplayNameAsLong
lpszTitleAsString
ulFlagsAsLong
lpfnCallbackAsLong
lParamAsLong
iImageAsLong
EndType
PrivateConstMAX_PATH=512&
PrivateConstBFFM_INITIALIZED=1&
PrivateConstBFFM_SELCHANGED=2&
PrivateConstWM_USER=&H400
PrivateConstBFFM_SETSTATUSTEXT=(WM_USER+100)
PrivateConstBFFM_SETSELECTION=(WM_USER+102)
PrivateConstWM_SETTEXT=&HC
PrivateConstBIF_RETURNONLYFSDIRS=1
"ole32.dll"(ByValhMemAsLong)
"shell32"(lpBIAsBrowseInfo)AsLong
"shell32.dll"Alias"SHGetPathFromIDListA"(ByValpidlAsLong,ByValpszPathAsString)AsLong
"user32.dll"Alias"SendMessageA"(ByValhwndAsLong,ByValwMsgAsLong,ByValwParamAsLong,lParamAsAny)AsLong
"user32"Alias"SendMessageW"(ByValhwndAsLong,ByValwMsgAsLong,ByValwParamAsLong,ByVallParamAsLong)AsLong
"user32"Alias"FindWindowExA"(ByValhWnd1AsLong,ByValhWnd2AsLong,ByVallpsz1AsString,ByVallpsz2AsString)AsLong
(AddAsLong)AsLong
GetAddressofFunction=Add
EndFunction
(ByValhwndAsLong,ByValuMsgAsLong,ByVallParamAsLong,ByVallpDataAsLong)AsLong
DimlpIDListAsLong
DimlRetAsLong
DimsBufferAsString
DimFhwndAsLong
DimszPath()AsByte
OnErrorGoToerrhandler
SelectCaseuMsg
CaseBFFM_INITIALIZED
CallSendMessage(hwnd,BFFM_SETSELECTION,True,ByValmSetPath)'传递默认路径
Fhwnd=FindWindowEx(hwnd,0,"Edit",vbNullString)
CallSendMessage(Fhwnd,WM_SETTEXT,0,ByValmSetPath)
CaseBFFM_SELCHANGED''路径变化
sBuffer=Space(MAX_PATH)
lRet=SHGetPathFromIDList(lParam,ByValsBuffer)
CoTaskMemFreelpIDList
IflRet=1Then
CallSendMessage(hwnd,BFFM_SETSTATUSTEXT,0,sBuffer)'改变对话框的状态信息
Fhwnd=FindWindowEx(hwnd,0,"Edit",vbNullString)
szPath=sBuffer
CallSendMessageLong(Fhwnd,WM_SETTEXT,0,VarPtr(szPath(0)))
EndIf
EndSelect
errhandler:
BrowseCallbackProc=0
EndFunction
'使用方法:
'Me.Caption=C_SelectPath(Me.hwnd,App.Path)'选择文件夹路径
PublicFunctionC_SelectPath(m_hwmd&,strPathAsString)AsString
DimlpIDListAsLong
DimudtBIAsBrowseInfo
WithudtBI'初试化udtBI结构
mSetPath=strPath'设置默认路径
.hWndOwner=m_hwmd
.ulFlags=BIF_RETURNONLYFSDIRSOr&H10Or&H40'&H10=路径框&H40=新建文件夹
.lpszTitle="请选择文件夹:"
.lpfnCallback=GetAddressofFunction(AddressOfBrowseCallbackProc)'getaddressoffunction.
EndWith
lpIDList=SHBrowseForFolder(udtBI)'弹出文件夹查看窗口
IflpIDListThen
DimsPathAsString,retAsLong
sPath=String$(MAX_PATH,0)
ret=SHGetPathFromIDList(ByVallpIDList,ByValsPath)
CallCoTaskMemFree(lpIDList)
IfretThen
C_SelectPath=Replace(sPath,Chr(0),"")
EndIf
EndIf
EndFunction
Ⅲ VB6 求 弹出选择 这一种 外观的文件夹 选择对话框,注意是要<文件夹>的,谢谢!
PrivateSubChooseDir_Click()
DimsTempDirAsString
OnErrorResumeNext
sTempDir=CurDir'
CommonDialog1.DialogTitle="Selectadirectory"'titlebar
CommonDialog1.InitDir=App.Path'startdir,mightbe"C:"orsoalso
CommonDialog1.FileName="SelectaDirectory"'Somethinginfilenamebox
CommonDialog1.Flags=cdlOFNNoValidate+cdlOFNHideReadOnly
CommonDialog1.Filter="Directories|*.~#~"'setfiles-filtertoshowdirsonly
CommonDialog1.CancelError=True'allowescapekey/cancel
CommonDialog1.ShowSave'showthedialogscreen
IfErr<>32755Then'Userdidn'tchoseCancel.
Me.SDir.Text=CurDir
EndIf
ChDirsTempDir'
EndSub
Ⅳ vb6.0 查找指定文件
Ⅳ VB6 如何先打开指定文件夹,然后选中指定该文件夹下指定的文件
Private Sub Command1_Click()
Shell "explorer.exe /select,C:\test\123.txt ", vbNormalFocus
End Sub
Ⅵ VB6 通过了Drive和Dir控件 选择路径
这两个控件界面都过时了,附件使用API调用通用对话框
分为选择文件夹browseDlg和选择文件FileDlg,调用方法见注释
Ⅶ VB6.0浏览文件夹对话框,怎么做
添加一个form2。把他当做弹出对话框,在form2中添加一个dirlistbox控件,在form1的command1的click事件中写入form2.show。在form2的dir1的click事件中写入form1.text1.text = dir1.path就OK了,避免使用繁琐的API函数
Ⅷ vb6 中 遍历指定文件夹中的文本文件
SubsFile(dAsString)
DimfsoAsObject,tdAsObject,ffAsObject,ddAsObject
Setfso=CreateObject("scripting.filesystemobject")
Settd=fso.getfolder(d)
ForEachffIntd.Files
IfLCase(Right(ff.Name,4))=".txt"ThenList1.AddItemff.Path
Next
IfCheck1.Value=1Then
ForEachddIntd.subfolders
sFiledd.Path
Next
EndIf
EndSub
PrivateSubCommand3_Click()
List1.Clear
sFileText2.Text
EndSub
Ⅸ vb6获取系统文件夹
PrivateSubCommand1_Click()
Debug.Print"通过Environ$函数获取:"
DimItem
DimiAsInteger
i=1
Item=Environ$(i)
DoUntilItem=""
Debug.PrintItem
i=i+1
Item=Environ$(i)'你可以查看一下全部环境串
Loop
'windir=C:WINDOWS'返回的串的格式是这样的
'Debug.PrintEnviron$("windir")'所以可以这样访问某个串
'如:
MsgBoxEnviron$("ProgramFiles")
'MsgBoxEnviron$("SystemRoot")
Debug.Print"也可以通过另外渠道获取:"
DimWshShellAsObject
SetWshShell=CreateObject("Wscript.Shell")
ForEachItemInWshShell.SpecialFolders'查看集合对象全部项目
Debug.PrintItem
Next
'也可以通过关键字访问某个项目,关键字是什么只能自己猜了,我没见到过完整的介绍。
'下面这几个是有效的:
MsgBoxWshShell.SpecialFolders("SendTo")
'MsgBoxWshShell.SpecialFolders("StartUp")
'MsgBoxWshShell.SpecialFolders("Desktop")
'MsgBoxWshShell.SpecialFolders("Recent")
EndSub
Ⅹ vb6 已经打开了一个文件夹,如何人工选定一个文件,然后对该文件进行其他操作
这是Windows问题,和钩子无关。
首先教你一个Exploer.exe的参数:
/select,<sub object>: 选中指定对象。如果使用"/select" , 则父目录被打开,并选中指定对象。
例:
explorer/select,C:
你在“开始”,“运行”中运行此命令,则会用文件夹方式打开C:WindowsSystem32driversetc这个目录,然后定位在文件hosts上。
你在Shell时完全可以这样做:
shell"explorer/select,""C:123""",vbNormalFocus
这样就能达到你要的效果了,至于读取文件内容,那看文件是什么格式的再去解决,这里无法回答。
不需要什么问题都想用钩子,多了解Windows各种机制或许解决问题会更简单些。