VB6调用API打开目标文件所在文件夹且选中目标文件
Option Explicit ' 模块名称: mOpenFolderAndSetFileFocus Private Declare Function SHCreateFromPath Lib "Shell32" Alias "ILCreateFromPathA" (ByVal lpFileName As String) As Long '增加判断文件是否存在 Private Type FILETIME Private Type WIN32_FIND_DATA Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" ( _ Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long Private Function FileExists(ByVal lpFileName As String) As Boolean '调用成功返回 True,否则返回 FalsePublic Function OpenFolderAndSetFileFocus(ByVal lpFileName As String) As Boolean On Error Resume Next Dim lngPidl As Long Dim lngRet As Long Dim strFile As String strFile = Trim(lpFileName) If FileExists(strFile) = False Then Exit Function lngPidl = SHCreateFromPath(strFile & vbNullChar) If lngPidl <> 0 Then lngRet = SHOpenFolderAndSelectItems(lngPidl,0) If lngRet = 0 Then OpenFolderAndSetFileFocus = True End If Call SHFree(lngPidl) End IfEnd Function (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |