zoukankan      html  css  js  c++  java
  • 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_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:  %s ",       szDeskTop);
        printf(
    "Favourites:  %s ",    szFavourites);
        printf(
    "Fonts:  %s ",         szFonts);
        printf(
    "My Document:  %s ",   szMyDocument);
        printf(
    "Program Files:  %s ", szProgramFiles);
        printf(
    "Programs:  %s ",      szPrograms);
        printf(
    "StartUp:  %s ",       szStartUp);
        printf(
    "Windows:  %s ",       szWindows);
    }

  • 相关阅读:
    关于systemgenerator的学习方法
    关于FPGA的非HDL设计方法比较
    vivado simlation post-implementation "not found module"问题分析
    快速重启tomcat的shell脚本
    python2 和python3报错:No module named ‘MySQLdb'”
    CentOS生产环境无网络安装percona-xtrabackup2.4【RPM安装教程】
    磁盘system ID解释
    对硬盘进行扩容,LVM逻辑卷创建案例实记
    LVS的原理
    毕业1年,我是如何走向运维工程师的
  • 原文地址:https://www.cnblogs.com/MakeView660/p/8663833.html
Copyright © 2011-2022 走看看