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. 【BIRT】报表显示不全

    使用BIRT开发了一张报表,预期效果如下 但是开发完成后预览效果如下: 最后的合计竟然没有了,那么怎么处理呢 鼠标点击Layout窗口空白部分,找到布局,切换为自动布局,如下图所示:

  2. 转载【微信支付】jsapi支付之传参问题(使用微信官方SDK之PHP版本) V3之WxpayPubHelper 亲测有效,V3WxpayAPI_php_v3.zip版未测试,理论上也是一样的。

    本文转载至:http://blog.csdn.net/geeklx/article/details/51146151 (微信支付现在分为v2版和v3版,2014年9月10号之前申请的为v2版,之后申请 ...

  3. C#DirectX播放视频

    文章地址:http://www.cnblogs.com/zhangjun1130/archive/2009/09/15/1566814.html 很多人第一次接触到DirectX大都是通过游戏,至于安 ...

  4. 用ping让对方电脑堵塞瘫痪

    用ping让对方电脑堵塞瘫痪2008-04-27 11:32 定义echo数据包大小. 在默认的情况下windows的ping发送的数据包大小为32byt,我们也可以自己定义它的大小, 但有一个大小的 ...

  5. mysql string types ---- mysql 字符类型详解

    一.mysql 中包涵的字符类型: [national] char [(m)] [character set charset_name] [collate collation_name] [natio ...

  6. INFORMIX的dbexport和dbimport使用示例说明

    INFORMIX-IDS数据库进行迁移中,我们在进行数据级别的迁移时,采用dbexport,dbimport来完成.dbexport导出数据库中所有对象的模式脚本和表数据文件,该模式脚本中包含有表等的 ...

  7. 以源码编译的方式安装PHP与php-fpm

    首先是最基本的下载,解压,编译安装(以PHP 5.3.6 为例): wget http://www.php.net/get/php-5.3.6.tar.gz/from/this/mirrortar x ...

  8. Redis C#入门

    redis-cli.exe 为客户端 redis-server.exe 为服务端 进行操作都是在客户端上操作,先随便添加一组 key value试一下: 再输入Get "键"名称, ...

  9. List<T>做数据源绑定的问题

    List<C_Pinpai> lc;// = new List<C_Pinpai>(); private void BindGrid() { //if (lc.Count &g ...

  10. Qcon2017实录|Service Mesh:下一代微服务

    https://zhuanlan.zhihu.com/p/30292372 数人云11月Meetup报名开启,看中西方大神如何论道云原生与微服务!本文作者敖小剑老师将在本次Meetup上继续分享Ser ...