| 发表于:2007-05-06 22:23:024楼 得分:7 |
我api和dir都写了,楼住参考一下吧 option explicit '********************************************************************************************************************** '搜索api函数、常量、类型等声明 private const invalid_handle_value = -1 private declare function findnextfile lib "kernel32 " alias "findnextfilea " (byval hfindfile as long, lpfindfiledata as win32_find_data) as long private declare function findclose lib "kernel32 " (byval hfindfile as long) as long private declare function findfirstfile lib "kernel32 " alias "findfirstfilea " (byval lpfilename as string, lpfindfiledata as win32_find_data) as long private wfd as win32_find_data private type filetime dwlowdatetime as long dwhighdatetime as long end type private const maxlfnpath = 260 private type win32_find_data dwfileattributes as long ftcreationtime as filetime ftlastaccesstime as filetime ftlastwritetime as filetime nfilesizehigh as long nfilesizelow as long dwreserved0 as long dwreserved1 as long cfilename as string * maxlfnpath cshortfilename as string * 14 end type '********************************************************************************************************************** '使listbox滚动条自动下拉等函数及常量声明 public declare function sendmessage lib "user32 " alias "sendmessagea " (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long private const wm_vscroll = &h115 private const sb_bottom = 7 '********************************************************************************************************************** '发送模拟按键消息 public declare function postmessage lib "user32 " alias "postmessagea " (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long public const bm_click = 245 public declare function messagebox lib "user32 " alias "messageboxa " (byval hwnd as long, byval lptext as string, byval lpcaption as string, byval wtype as long) as long '********************************************************************************************************************** 'ispause标识是不是处于暂停中,issearch标识是不是处于文件搜索中,isstop是否处于停止状态 public ispause as boolean, issearch as boolean, isstop as boolean '搜索指定路径并且包括子路径 public sub searcheruserapi(byval strcurpath as string, optional byval ischecksub as boolean = true) static sum as long if right(strcurpath, 1) <> "\ " then strcurpath = strcurpath & "\ " dim dirs as long, dirbuf() as string, i as integer, hitem as long, k as long, strtmp as string hitem = findfirstfile(strcurpath & "*.* ", wfd) if hitem <> invalid_handle_value then do if isstop then exit do sum = sum + 1 if sum mod 20 = 0 then doevents '检查是不是目录 if (wfd.dwfileattributes and vbdirectory) then ' 检查是不是 ". " or ".. " if asc(wfd.cfilename) <> 46 then redim preserve dirbuf(0 to dirs) dirbuf(dirs) = left(wfd.cfilename, instr(wfd.cfilename, vbnullchar) - 1) dirs = dirs + 1 strtmp = strcurpath & left(wfd.cfilename, instr(wfd.cfilename, vbnullchar) - 1) frmmain.lstfolders.additem strtmp sendmessage frmmain.lstfolders.hwnd, wm_vscroll, sb_bottom, 0& end if else strtmp = strcurpath & left(wfd.cfilename, instr(wfd.cfilename, vbnullchar) - 1) frmmain.lstfiles.additem strtmp sendmessage frmmain.lstfiles.hwnd, wm_vscroll, sb_bottom, 0& end if loop while findnextfile(hitem, wfd) call findclose(hitem) end if if not ischecksub then exit sub for i = 0 to dirs - 1 if isstop then exit for searcheruserapi strcurpath & dirbuf(i) & "\ " next i end sub public sub seacheruserdir(byval strpath as string, optional byval ischecksub as boolean = true) static sum as long dim strfolders() as string, dirs as integer, i as integer if right(strpath, 1) <> "\ " then strpath = strpath & "\ " dim strtmp as string on error resume next strtmp = dir(strpath & "*.* ", 1 or 2 or 4 or vbdirectory) do while strtmp <> " " if isstop then exit do sum = sum + 1 if sum mod 20 = 0 then doevents if getattr(strpath & strtmp) and vbdirectory then if left(strtmp, 1) <> ". " then frmmain.lstfolders.additem strpath & strtmp sendmessage frmmain.lstfolders.hwnd, wm_vscroll, sb_bottom, 0& redim preserve strfolders(0 to dirs) strfolders(dirs) = strpath & strtmp & "\ " dirs = dirs + 1 end if else frmmain.lstfiles.additem strpath & strtmp sendmessage frmmain.lstfiles.hwnd, wm_vscroll, sb_bottom, 0& end if strtmp = dir loop if not ischecksub then exit sub for i = 0 to dirs - 1 if isstop then exit for seacheruserdir strfolders(i), ischecksub next end sub public sub restorepublic() isstop = false ispause = false issearch = false end sub | | |
|