博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SHGetSpecialFolderPath用法
阅读量:4942 次
发布时间:2019-06-11

本文共 4052 字,大约阅读时间需要 13 分钟。

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

Syntax

BOOL SHGetSpecialFolderPath(  HWND ,  LPTSTR ,  int ,  BOOL );

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]          = {
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);
}

 

转载于:https://www.cnblogs.com/MakeView660/p/8663833.html

你可能感兴趣的文章
<metro>Google的验证
查看>>
SQL中NUMERIC和DECIMAL的区别
查看>>
安卓课程设计:微课表
查看>>
Oracle 表的分组操作
查看>>
在OS X上的Intllij Idea中配置GlassFish
查看>>
用查表法快速转换yv12到RGB【转】
查看>>
使用公钥登录SSL
查看>>
hdu 1290_献给杭电五十周年校庆的礼物
查看>>
Nginx 入门
查看>>
openCR-用ROS代码点亮LED的方法
查看>>
豆瓣电影api
查看>>
BufferedInputStream和FileInputStream的区别
查看>>
二阶段之六
查看>>
微博爬虫 python
查看>>
中石油 【递归】普通递归关系
查看>>
vue报错Error in render: "TypeError: Cannot read property '0' of undefined"
查看>>
silverlight 隐藏ChildWindow 右上角的关闭按钮
查看>>
likely() 和 unlikely()
查看>>
03一些View总结
查看>>
MapReduce--平均分,最高,低分以及及格率的计算
查看>>