SHGetSpecialFolderPath 一个很有用的API

        VB取系统文件夹,有很多API,如GetSystemDirectoryA可以得到SYSTEM32系统文件夹,GetTempPathA得到临时文件夹,GetWindowsDirectoryA得到windows文件夹。这里再介绍一个有用的API
      - SHGetSpecialFolderPath ,这个api除了能得到以上列举的文件夹,还能得到更多的系统文件夹。
      具体用法:
      声明API: function ulong SHGetSpecialFolderPath(long hwndOwner,ref string
      lpszPath,int nFolder,boolean fCreate ) LIBRARY "shell32.dll" ALIAS FOR
      "SHGetSpecialFolderPathA"
      Function Long GetDesktopWindow() Library 'user32.dll'

      hwndOwner :用GetDesktopWindow API取一个窗口句柄。
      lpszPath:返回的路径
      nFolder:标识代号
      fCreate:true :如果文件夹不存在则创建,false:不创建
      lpszPath和nFolder对应关系:
            nFolderlpszPath
            0C:/Documents and Settings/当前用户/桌面
            2C:/Documents and Settings/当前用户/「开始」菜单/程序
            5C:/Documents and Settings/当前用户/My Documents
            6C:/Documents and Settings/当前用户/Favorites
            7C:/Documents and Settings/当前用户/「开始」菜单/程序/启动
            8C:/Documents and Settings/当前用户/Recent
            9C:/Documents and Settings/当前用户/SendTo
            11C:/Documents and Settings/当前用户/「开始」菜单
            13C:/Documents and Settings/当前用户/My Documents/My Music
            14C:/Documents and Settings/当前用户/My Documents/My Videos
            16C:/Documents and Settings/当前用户/桌面
            19C:/Documents and Settings/当前用户/NetHood
            20C:/WINDOWS/Fonts
            21C:/Documents and Settings/当前用户/Templates
            22C:/Documents and Settings/All Users/「开始」菜单
            23C:/Documents and Settings/All Users/「开始」菜单/程序
            24C:/Documents and Settings/All Users/「开始」菜单/程序/启动
            25C:/Documents and Settings/All Users/桌面
            26C:/Documents and Settings/当前用户/Application Data
            27C:/Documents and Settings/当前用户/PrintHood
            28C:/Documents and Settings/当前用户/Local Settings/Application Data
            31C:/Documents and Settings/All Users/Favorites
            32C:/Documents and Settings/当前用户/Local Settings/Temporary Internet
            Files
            33C:/Documents and Settings/当前用户/Cookies
            34C:/Documents and Settings/当前用户/Local Settings/History
            35C:/Documents and Settings/All Users/Application Data
            36C:/WINDOWS
            37C:/WINDOWS/system32
            38C:/Program Files

            39C:/Documents and Settings/当前用户/My Documents/My Pictures
            40C:/Documents and Settings/当前用户
            43C:/Program Files/Common Files
            45C:/Documents and Settings/All Users/Templates
            46C:/Documents and Settings/All Users/Documents
            47C:/Documents and Settings/All Users/「开始」菜单/程序/管理工具
            48C:/Documents and Settings/当前用户/「开始」菜单/程序/管理工具
            53C:/Documents and Settings/All Users/Documents/My Music
            54C:/Documents and Settings/All Users/Documents/My Pictures
            55C:/Documents and Settings/All Users/Documents/My Videos
            56C:/WINDOWS/resources
            59C:/Documents and Settings/当前用户/Local Settings/Application
            Data/Microsoft/CD Burning

      函数写法:
      //====================================================================
      // 函数: u_fun::uf_directory_get()
      //--------------------------------------------------------------------
      // 描述: 取系统文件夹
      //--------------------------------------------------------------------
      // 参数:
      //   value integer ai_folder 
      //--------------------------------------------------------------------
      // 返回:   string
      //--------------------------------------------------------------------
      // 作者: 程宁   日期: 2007.05.15
      //--------------------------------------------------------------------
      // 修改历史:
      //
      //====================================================================
      string ret
      long ll_null
      ret=space(255)
      SHGetSpecialFolderPath(GetDesktopWindow(), ret ,ai_folder,false)
      return ret 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值