VB Shell32 的外壳函数库 代码

这段代码展示了如何在Visual Basic中使用Shell32库进行文件操作,包括浏览文件夹、获取特殊文件夹路径、格式化驱动器等。通过声明并调用如SHBrowseForFolder、SHGetSpecialFolderLocation等函数,实现用户交互和系统级操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Attribute VB_Name  =   " Shell32Function "
Option   Explicit
Private   Declare   Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Long, pSrc As LongByVal ByteLen As Long)

Private Declare Function SHBrowseForFolder Lib "shell32" Alias "SHBrowseForFolderA" ( _
                                                lpBrowseInfo 
As BROWSEINFO) As Long

Private Declare Function SHGetSpecialFolderLocation Lib "shell32" ( _
                                                
ByVal hwndOwner As Long, _
                                                
ByVal nFolder As Long, _
                                                pIdl 
As ITEMIDLIST) As Long
                                                
'Private Declare Function SHGetFileInfo Lib "shell32" Alias "SHGetFileInfoA" ( _
                                                ByVal pszPath As Any, _
                                                
ByVal dwFileAttributes As Long, _
                                                psfi 
As SHFILEINFO, _
                                                
ByVal cbFileInfo As Long, _
                                                
ByVal uFlags As LongAs Long
                                                
Private Declare Function ShellAbout Lib "shell32" Alias "ShellAboutA" ( _
                                                
ByVal hwnd As Long, _
                                                
ByVal szApp As String, _
                                                
ByVal szOtherStuff As String, _
                                                
ByVal HIcon As LongAs Long
                                                
Private Declare Function SHGetPathFromIDList Lib "shell32" Alias "SHGetPathFromIDListA" ( _
                                                
ByVal pIdl As Long, _
                                                
ByVal pszPath As StringAs Long
                                                
'Private Declare Function SHAddToRecentDocs Lib "shell32" ( _
                                                ByVal uFlags As Long, _
                                                
ByVal pV As String)
                                                
                                                
Private Declare Function SHFormatDrive Lib "shell32" ( _
                                                hwnd 
As Long, _
                                                iDrive 
As Long, _
                                                iCapacity 
As Long, _
                                                iType 
As LongAs Long
                                                
Private Declare Sub CoTaskMemFree Lib "ole32" (ByVal pV As Long)

Private Type SHITEMID
    cb 
As Long
    abID() 
As Byte
End Type

Private Type ITEMIDLIST
    mkid 
As SHITEMID
End Type

Private Type BROWSEINFO
    hOwner 
As Long
    pidlRoot 
As Long
    pszDisplayName 
As String
    lpszTitle 
As String
    ulFlags 
As Long
    lpfn 
As Long
    lParam 
As Long
    iImage 
As Long
End Type
Private Const MAX_PATH = 260

'Private Type SHFILEINFO
'
    HIcon As Long
'
    iIcon As Long
'
    dwAttributes As Long
'
    szDisplayName As String * MAX_PATH
'
    szTypeName As String * 80
'
End Type
Private Const ERROR_SUCCESS = 0&


Private Const CSIDL_DESKTOP = &H0                           '// <desktop>
Private Const CSIDL_INTERNET = &H1                          '// Internet Explorer (icon on desktop)
Private Const CSIDL_PROGRAMS = &H2                          '// Start MenuPrograms
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值