CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  基础类

如何用VB6浏览文件夹?

楼主LuKoo(LuKoo)2000-09-24 23:28:00 在 VB / 基础类 提问

如何用VB6浏览文件夹?就象安装程序时选择目录那种,不要用控件,用API函数.  
  谢谢! 问题点数:60、回复次数:4Top

1 楼lumine(源点)回复于 2000-09-25 10:11:00 得分 20

Please   Try   it,   it   can   show   browse   folder   when   your   form   load.  
  Good   Luck!  
   
   
  Private   Type   BrowseInfo  
        hWndOwner             As   Long  
        pIDLRoot               As   Long  
        pszDisplayName   As   Long  
        lpszTitle             As   Long  
        ulFlags                 As   Long  
        lpfnCallback       As   Long  
        lParam                   As   Long  
        iImage                   As   Long  
  End   Type  
   
   
   
  Private   Declare   Function   SHBrowseForFolder   Lib   "shell32"   _  
                                                                      (lpbi   As   BrowseInfo)   As   Long  
   
   
  Private   Sub   Form_Load()  
          Dim   dd   As   BrowseInfo  
          a   =   SHBrowseForFolder(dd)  
  End   Sub  
  Top

2 楼LuKoo(LuKoo)回复于 2000-09-25 11:09:00 得分 0

to   lumine:谢谢你!浏览文件夹能够显示,请问怎么得到选择文件夹的字符串?Top

3 楼playyuer(退休干部 卧鼠藏虫)回复于 2000-09-25 12:34:00 得分 40

 
  Start   a   new   Standard   EXE   project   in   Visual   Basic.   Form1   is   created   by   default.    
   
  Add   a   CommandButton   to   Form1.    
   
  Copy   the   following   code   to   the   Code   window   of   Form1:    
   
   
              Option   Explicit  
   
   
   
              Private   Const   BIF_RETURNONLYFSDIRS   =   1  
              Private   Const   BIF_DONTGOBELOWDOMAIN   =   2  
              Private   Const   MAX_PATH   =   260  
   
   
   
              Private   Declare   Function   SHBrowseForFolder   Lib   "shell32"   _  
                                                                                  (lpbi   As   BrowseInfo)   As   Long  
   
              Private   Declare   Function   SHGetPathFromIDList   Lib   "shell32"   _  
                                                                                  (ByVal   pidList   As   Long,   _  
                                                                                  ByVal   lpBuffer   As   String)   As   Long  
   
              Private   Declare   Function   lstrcat   Lib   "kernel32"   Alias   "lstrcatA"   _  
                                                                                  (ByVal   lpString1   As   String,   ByVal   _  
                                                                                  lpString2   As   String)   As   Long  
   
              Private   Type   BrowseInfo  
                    hWndOwner             As   Long  
                    pIDLRoot               As   Long  
                    pszDisplayName   As   Long  
                    lpszTitle             As   Long  
                    ulFlags                 As   Long  
                    lpfnCallback       As   Long  
                    lParam                   As   Long  
                    iImage                   As   Long  
              End   Type  
   
              Private   Sub   Command1_Click()  
              'Opens   a   Treeview   control   that   displays   the   directories   in   a   computer  
   
                    Dim   lpIDList   As   Long  
                    Dim   sBuffer   As   String  
                    Dim   szTitle   As   String  
                    Dim   tBrowseInfo   As   BrowseInfo  
   
                    szTitle   =   "This   is   the   title"  
                    With   tBrowseInfo  
                          .hWndOwner   =   Me.hWnd  
                          .lpszTitle   =   lstrcat(szTitle,   "")  
                          .ulFlags   =   BIF_RETURNONLYFSDIRS   +   BIF_DONTGOBELOWDOMAIN  
                    End   With  
   
                    lpIDList   =   SHBrowseForFolder(tBrowseInfo)  
   
                    If   (lpIDList)   Then  
                          sBuffer   =   Space(MAX_PATH)  
                          SHGetPathFromIDList   lpIDList,   sBuffer  
                          sBuffer   =   Left(sBuffer,   InStr(sBuffer,   vbNullChar)   -   1)  
                          MsgBox   sBuffer  
                    End   If  
              End   Sub  
   
   
   
  On   the   Run   menu,   click   Start   or   press   the   F5   key   to   start   the   program.   Click   the   CommandButton   to   display   the   directory   structure   of   the   computer.   Select   a   directory   and   click   the   OK   button   to   display   the   directory   you   selected   in   a   message   box.    
  Top

4 楼luhaifeng(心雨)回复于 2001-01-14 22:55:00 得分 0

若用控件又该怎么办?Top

相关问题

  • 如何浏览文件夹?
  • 如何用vb建立文件夹?
  • 浏览文件夹时如何定位到特定的文件夹?
  • 如何创建“资源浏览器”->所有文件夹的TreeView。
  • 如何使浏览器打开一个文件夹?
  • 浏览文件夹对话框如何复初值
  • 如何用"文件夹浏览"对话框
  • 如何调用浏览文件夹对话框
  • 如何实现 浏览文件夹对话框??
  • 如何制作FolderBrowser 系统文件夹浏览器控件?

关键词

  • vb6
  • 文件夹
  • 浏览
  • vb
  • shell
  • code
  • browseinfo
  • shbrowseforfolder
  • 用vb6浏览文件夹
  • lpbi

得分解答快速导航

  • 帖主:LuKoo
  • lumine
  • playyuer

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo