用户登录  |  用户注册
首 页商业源码原创产品编程论坛
当前位置:PB创新网文章中心编程技巧VisualBasic

往列表框中填入文件目录信息

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-03-16 19:48:00
This routine demonstrated using the API and a standard listbox to duplicate the functionality of a FileList Box. By using this method over the FileListBox, you can control the files, directories and drives displayed. 

 Note however that the constant value for ''READWRITE'' is 0, the same as the vb constant ''Archive''. In VB you can not mask out the archive files to only return hidden files (for example). But by using the API value DDL_EXCLUSIVE Or''d with the type to be listed, you have control over the display of files.

 The added bonus is that this method is instantaneous.

 Add the following code to a BAS module:
---------------------------------------------------------------

Public Declare Function SendMessageStr Lib _
 "user32" Alias "SendMessageA" _
 (ByVal hwnd As Long, _
  ByVal wMsg As Long, _
  ByVal wParam As Long, _
  ByVal lParam As String) As Long

Public Declare Function SendMessageLong Lib _
  "user32" Alias "SendMessageA" _
  (ByVal hwnd As Long, _
  ByVal wMsg As Long, _
  ByVal wParam As Long, _
  ByVal lParam As Long) As Long

Public Const LB_DIR = &H18D
Public Const LB_RESETCONTENT = &H184

Public Const DDL_READWRITE = &H0
Public Const DDL_READONLY = &H1
Public Const DDL_HIDDEN = &H2
Public Const DDL_SYSTEM = &H4
Public Const DDL_DIRECTORY = &H10
Public Const DDL_ARCHIVE = &H20
Public Const DDL_DRIVES = &H4000
Public Const DDL_EXCLUSIVE = &H8000
Public Const DDL_POSTMSGS = &H2000
Public Const DDL_FLAGS = DDL_ARCHIVE Or DDL_DIRECTORY
''--end block--

-------------------------------------------------------------------
 Create a form containing six command buttons in a control array (Command1(0) - Command1(5)), and a listbox. Add the following code to the form:

-------------------------------------------------------------------

Private Sub Command1_Click(Index As Integer)

  Dim r As Long
  Dim DDL_FLAGS As Long
  Dim searchPath As String

  searchPath = "c:\win\*.*"

  Select Case Index
   Case 0: DDL_FLAGS = DDL_EXCLUSIVE Or DDL_ARCHIVE
   Case 1: DDL_FLAGS = DDL_EXCLUSIVE Or DDL_ARCHIVE Or DDL_DIRECTORY
   Case 2: DDL_FLAGS = DDL_EXCLUSIVE Or DDL_HIDDEN
   Case 3: DDL_FLAGS = DDL_EXCLUSIVE Or DDL_SYSTEM
   Case 4: DDL_FLAGS = DDL_EXCLUSIVE Or DDL_DIRECTORY
   Case 5: DDL_FLAGS = DDL_EXCLUSIVE Or DDL_DRIVES
   Case Else
  End Select

 ''clear and populate the listbox
  Call SendMessageLong(List1.hwnd, LB_RESETCONTENT, 0, 0)
  Call SendMessageStr(List1.hwnd, LB_DIR, DDL_FLAGS, ByVal searchPath)

  Label1 = r + 1 & " " & Command1(Index).Caption & " found."

End Sub
''--end block--
-------------------------------------------------------------------

 By changing the value of the DDL_FLAGS parameter to include or exclude specific DDL_ constants, you determine the type of file structure to include into the list.

 For an explanation of my usage of SendMessageLong and SendMessageStr, see Using the Windows SendMessage API Successfully in the Resource Centre.

Tags:

作者:佚名

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
PB创新网ourmis.com】Copyright © 2000-2009 . All Rights Reserved .
页面执行时间:28,515.63000 毫秒
Email:ourmis@126.com QQ:2322888 蜀ICP备05006790号