SHGetSpecialFolderPath用法

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:

CSIDLValueDescription
CSIDL_DESKTOP0x0000Not supported on Smartphone.
CSIDL_FAVORITES0x0006The file system directory that serves as a common repository for the user's favorite items.
CSIDL_FONTS0x0014The virtual folder that contains fonts.
CSIDL_PERSONAL0x0005The file system directory that serves as a common repository for documents.
CSIDL_PROGRAM_FILES0x0026The program files folder.
CSIDL_PROGRAMS0x0002The file system directory that contains the user's program groups, which are also file system directories.
CSIDL_STARTUP0x0007The file system directory that corresponds to the user's Startup program group. The system starts these programs when a device is powered on.
CSIDL_WINDOWS0x0024The 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]          = {
0 };
    CHAR szFavourites[MAX_PATH]       = {
0 };
    CHAR szFonts[MAX_PATH]             = {
0 };
    CHAR szMyDocument[MAX_PATH]     = {
0 };
    CHAR szProgramFiles[MAX_PATH]   = {
0 };
    CHAR szPrograms[MAX_PATH]       = {
0 };
    CHAR szStartUp[MAX_PATH]        = {
0 };
    CHAR szWindows[MAX_PATH]        = {
0 };

    
// 使用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);
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值