Login dark

title: SHGetSpecialFolderPath获取特殊路径
author: Love02xp
date: 2018-11-12 10:01:26
category: [编程代码]
tags: [VC6,编程]
draft: false
cover:
preview:



##### [阅读原文]()




SHGetSpecialFolderPath获取特殊路径 

VB格式:

Option Explicit Declare Function SHGetSpecialFolderPath Lib "shell32.dll" Alias "SHGetSpecialFolderPathA" (ByVal hwnd As Long, ByVal pszPath As String, ByVal csidl As Long, ByVal fCreate As Long) As Long
Const MAX_PATH As Long = 260
Const CSIDL_PERSONAL As Long = 5

Sub Main()

Dim sPath As String
sPath = Space(MAX_PATH) & Chr(0)     

SHGetSpecialFolderPath 0, sPath, CSIDL_PERSONAL, 0
Debug.Print sPath

End Sub
注意:Alias "SHGetSpecialFolderPathA" 不能省略



<!--more-->



VC格式:

BOOL SHGetSpecialFolderPath (

         HWND hwndOwner,

         LPTSTR lpszPath,

         int nFolder,

         BOOL fCreate

);

hwndOwner :用GetDesktopWindow API取一个窗口句柄。

lpszPath:返回的路径

nFolder:标识代号

fCreate:true :如果文件夹不存在则创建,false:不创建



    TCHAR   szPath[MAX_PATH]; 
    int   iRet; 
    memset(szPath,   0,   sizeof(szPath)); 
    iRet   =   SHGetSpecialFolderPath(NULL,   szPath,   CSIDL_STARTMENU,   0); 
    if(TRUE   ==   iRet) 
    { 
    } 



其他:

lpszPath和nFolder对应关系:



nFolder lpszPath
0 C:Documents and Settings当前用户桌面
2 C:Documents and Settings当前用户「开始」菜单程序
5 C:Documents and Settings当前用户My Documents
6 C:Documents and Settings当前用户Favorites
7 C:Documents and Settings当前用户「开始」菜单程序启动
8 C:Documents and Settings当前用户Recent
9 C:Documents and Settings当前用户SendTo
11 C:Documents and Settings当前用户「开始」菜单
13 C:Documents and Settings当前用户My DocumentsMy Music
14 C:Documents and Settings当前用户My DocumentsMy Videos
16 C:Documents and Settings当前用户桌面
19 C:Documents and Settings当前用户NetHood
20 C:WINDOWSFonts
21 C:Documents and Settings当前用户Templates
22 C:Documents and SettingsAll Users「开始」菜单
23 C:Documents and SettingsAll Users「开始」菜单程序
24 C:Documents and SettingsAll Users「开始」菜单程序启动
25 C:Documents and SettingsAll Users桌面
26 C:Documents and Settings当前用户Application Data
27 C:Documents and Settings当前用户PrintHood
28 C:Documents and Settings当前用户Local SettingsApplication Data
31 C:Documents and SettingsAll UsersFavorites
32 C:Documents and Settings当前用户Local SettingsTemporary Internet Files
33 C:Documents and Settings当前用户Cookies
34 C:Documents and Settings当前用户Local SettingsHistory
35 C:Documents and SettingsAll UsersApplication Data
36 C:WINDOWS
37 C:WINDOWSsystem32
38 C:Program Files
39 C:Documents and Settings当前用户My DocumentsMy Pictures
40 C:Documents and Settings当前用户
43 C:Program FilesCommon Files
45 C:Documents and SettingsAll UsersTemplates
46 C:Documents and SettingsAll UsersDocuments
47 C:Documents and SettingsAll Users「开始」菜单程序管理工具
48 C:Documents and Settings当前用户「开始」菜单程序管理工具
53 C:Documents and SettingsAll UsersDocumentsMy Music
54 C:Documents and SettingsAll UsersDocumentsMy Pictures
55 C:Documents and SettingsAll UsersDocumentsMy Videos
56 C:WINDOWSresources
59 C:Documents and Settings当前用户Local SettingsApplication DataMicrosoftCD Burning