The SHGetSpecialFolderPath function retrieves the path of a special folder that is identified by its CSIDL.

Syntax

BOOL SHGetSpecialFolderPath(
HWND hwndOwner,
LPTSTR lpszPath,
int nFolder,
BOOL fCreate
);

Parameters

hwndOwner
[in] Handle to the owner window the client should specify if it displays a dialog box or message box.
lpszPath
[in] Reference to a character buffer that receives the drive and path of the specified folder. This buffer must be at least MAX_PATH characters in size.
nFolder
[in] CSIDL that identifies the folder of interest. If a virtual folder is specified, this function fails. See Remarks for possible values.
fCreate
[in] Indicates whether the folder should be created if it does not already exist. If this value is nonzero, the folder is created. If this value is zero, the folder is not created.

Return Values

For Windows Mobile 2003 and later, returns TRUE if successful, FALSE otherwise. For Windows Mobile 2002 and earlier, returns FALSE even if successful. If the folder represented by the nFolder parameter does not exist and is not created, a NULL string is returned indicating that the directory does not exist.

Remarks

A number of folders are used frequently by applications but might not have the same name or location on any given system. CSIDL values provide a system-independent way to identify these special folders. These values supersede the use of environment variables for this purpose.

The following table lists valid CSIDL values for the nFolder parameter:

CSIDL Value Description
CSIDL_DESKTOP 0x0000 Not supported on Smartphone.
CSIDL_FAVORITES 0x0006 The file system directory that serves as a common repository for the user's favorite items.
CSIDL_FONTS 0x0014 The virtual folder that contains fonts.
CSIDL_PERSONAL 0x0005 The file system directory that serves as a common repository for documents.
CSIDL_PROGRAM_FILES 0x0026 The program files folder.
CSIDL_PROGRAMS 0x0002 The file system directory that contains the user's program groups, which are also file system directories.
CSIDL_STARTUP 0x0007 The file system directory that corresponds to the user's Startup program group. The system starts these programs when a device is powered on.
CSIDL_WINDOWS 0x0024 The Windows folder.

The CSIDL_DESKTOP value is invalid for the Smartphone platform. Smartphone uses a home screen instead of a desktop; do not use this CSIDL value within the Smartphone development environment.

  进行 Shell 程序的设计,需要使用一些头文件和库文件。

一般 Shell API 都在 shlobj.h 头文件中声明,由 Shell32.dll 导出,链接时需要使用到 Shell32.lib 库。

 C++ Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
/*************************************
* VOID GetSpecialFolderQS()
* 功能    SHGetSpecialFolderPath用法
*
* 参数    未使用
**************************************/
VOID GetSpecialFolderQS()
{
    CHAR szDeskTop[MAX_PATH]          = {};
    CHAR szFavourites[MAX_PATH]       = {};
    CHAR szFonts[MAX_PATH]             = {};
    CHAR szMyDocument[MAX_PATH]     = {};
    CHAR szProgramFiles[MAX_PATH]   = {};
    CHAR szPrograms[MAX_PATH]       = {};
    CHAR szStartUp[MAX_PATH]        = {};
    CHAR szWindows[MAX_PATH]        = {};

// 使用SHGetSpecialFolderPath获取特殊目录路径
    SHGetSpecialFolderPath(NULL, szDeskTop,         CSIDL_DESKTOP,          FALSE);
    SHGetSpecialFolderPath(NULL, szFavourites,      CSIDL_FAVORITES,        FALSE);
    SHGetSpecialFolderPath(NULL, szFonts,           CSIDL_FONTS,            FALSE);
    SHGetSpecialFolderPath(NULL, szMyDocument,      CSIDL_PERSONAL,         FALSE);
    SHGetSpecialFolderPath(NULL, szProgramFiles,    CSIDL_PROGRAM_FILES,    FALSE);
    SHGetSpecialFolderPath(NULL, szPrograms,        CSIDL_PROGRAMS,         FALSE);
    SHGetSpecialFolderPath(NULL, szStartUp,         CSIDL_STARTUP,          FALSE);
    SHGetSpecialFolderPath(NULL, szWindows,         CSIDL_WINDOWS,          FALSE);
    printf("DeskTop:\t %s\n",       szDeskTop);
    printf("Favourites:\t %s\n",    szFavourites);
    printf("Fonts:\t %s\n",         szFonts);
    printf("My Document:\t %s\n",   szMyDocument);
    printf("Program Files:\t %s\n", szProgramFiles);
    printf("Programs:\t %s\n",      szPrograms);
    printf("StartUp:\t %s\n",       szStartUp);
    printf("Windows:\t %s\n",       szWindows);
}

SHGetSpecialFolderPath用法的更多相关文章

  1. EditText 基本用法

    title: EditText 基本用法 tags: EditText,编辑框,输入框 --- EditText介绍: EditText 在开发中也是经常用到的控件,也是一个比较必要的组件,可以说它是 ...

  2. jquery插件的用法之cookie 插件

    一.使用cookie 插件 插件官方网站下载地址:http://plugins.jquery.com/cookie/ cookie 插件的用法比较简单,直接粘贴下面代码示例: //生成一个cookie ...

  3. Java中的Socket的用法

                                   Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...

  4. [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法

    一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...

  5. python enumerate 用法

    A new built-in function, enumerate() , will make certain loops a bit clearer. enumerate(thing) , whe ...

  6. [转载]Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结

    本文对Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法进行了详细的总结,需要的朋友可以参考下,希望对大家有所帮助. 详细解读Jquery各Ajax函数: ...

  7. 【JavaScript】innerHTML、innerText和outerHTML的用法区别

    用法: <div id="test">   <span style="color:red">test1</span> tes ...

  8. chattr用法

    [root@localhost tmp]# umask 0022 一.chattr用法 1.创建空文件attrtest,然后删除,提示无法删除,因为有隐藏文件 [root@localhost tmp] ...

  9. 萌新笔记——vim命令“=”、“d”、“y”的用法(结合光标移动命令,一些场合会非常方便)

    vim有许多命令,网上搜有一堆贴子.文章列举出各种功能的命令. 对于"="."d"."y",我在无意中发现了它们所具有的相同的一些用法,先举 ...

随机推荐

  1. vcs github gitlab git名词解释

    vcs:version control system git:一个版本管理工具,从git上clone,除了代码,还会把版本信息也给你clone下来. github:一个基于git的代码管理网站,支持公 ...

  2. Intellij IDEA 14使用maven3.3.3 问题

    Intellij IDEA 14使用maven3.3.3报错: -Dmaven.multiModuleProjectDirectory system propery is not set. Check ...

  3. 【jQuery+html】JS如何在html页面获取PHP输出的变量

    如题:JS如何获取php输出到模板HTML的变量呢? 废话不多说,自己看. aa.html <!-- 前提在HTML文件中--> <script type="text/ja ...

  4. centos 配置 samba 与windows共享文件夹

    yum install samba /etc/samba/smb.conf directory mask = 0777 ← 指定新建目录的属性(以下4行) force directory mode = ...

  5. poj 1236 Network of Schools 【Tarjan】

    题目链接:http://poj.org/problem?id=1236 题意: 本题为有向图. 需解决两个问题: 1 须要给多少个点,才干传遍全部点. 2 加多少条边,使得整个图变得强连通. 使用Ta ...

  6. numpy.argmin 使用

    https://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.argmin.html numpy.argmin(a, axis=N ...

  7. 点滴积累【other】---HTTP Error 503. The service is unavailable (转载)

    此文参考来源:http://luowei1371984.blog.163.com/blog/static/440415892012726448381/ 描述:在访问网站是会遇到这样的问题,提示“HTT ...

  8. php检测iis环境是否支持htaccess

    php检测iis环境是否支持htaccess的方法. modrewrite.php <?php echo "mod_rewrite works"; ?> open_me ...

  9. redmine 的安装

    https://bitnami.com/stack/redmine/installer#官方地址 安装很简单,给权限 chmod +x bitnami-redmine-3.3.0-1-linux-x6 ...

  10. oracle中空值null的判断和转换:NVL的用法

    1.NULL空值概念 数据库里有一个很重要的概念:空值即NULL.有时表中,更确切的说是某些字段值,可能会出现空值, 这是因为这个数据不知道是什么值或根本就不存在. 2.NULL空值判断 空值不等同于 ...