zoukankan      html  css  js  c++  java
  • Windows API 第二篇 SHGetSpecialFolderPath

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

    参数解释:

    hwndOwnerHandle to the owner window the client should specify if it displays a dialog box or message box.

    lpszPathPointer to a null-terminated string that receives the drive and path of the specified folder. This buffer must be at least MAX_PATH characters in size

    nFolder:A CSIDL that identifies the folder of interest. If a virtual folder is specified, this function will fail.

    fCreate:Indicates if the folder should be created if it does not already exist. If this value is nonzero, the folder will be created. If this value is zero, the folder will not be created.

    一个简单的test
    建立控制台程序:

    #include "stdafx.h"
    #include <Windows.h>
    #include <string>
    #include <Shlobj.h>
    
    using namespace std;;
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        WCHAR szPath[MAX_PATH + 1] = { 0 };
        wstring strMsgW;
    
        BOOL bRet;
        //严格一点,每个返回值要判断
        bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_PROGRAM_FILES, FALSE);
        strMsgW.append(L"CSIDL_PROGRAM_FILES: ");
        strMsgW.append(szPath);
        strMsgW.append(L"
    ");
    
        bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_PROGRAM_FILES_COMMON, FALSE);
        strMsgW.append(L"CSIDL_PROGRAM_FILES_COMMON: ");
        strMsgW.append(szPath);
        strMsgW.append(L"
    ");
    
        bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_SYSTEM, FALSE);
        strMsgW.append(L"CSIDL_SYSTEM: ");
        strMsgW.append(szPath);
        strMsgW.append(L"
    ");
    
        bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_STARTUP , FALSE);
        strMsgW.append(L"CSIDL_STARTUP: ");
        strMsgW.append(szPath);
        strMsgW.append(L"
    ");
    
        bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_APPDATA , FALSE);
        strMsgW.append(L"CSIDL_APPDATA: ");
        strMsgW.append(szPath);
        strMsgW.append(L"
    ");
    
        MessageBox(NULL, strMsgW.c_str(), L"SHGetSpecialFolderPath Test", MB_OK);
    
        return 0;
    }
    
    运行结果:
    
    Windows API 第二篇  SHGetSpecialFolderPath - grown-up - work labor and play
  • 相关阅读:
    Typora标题自动编号+设定快捷键技巧
    配置redis 4.0.11 集群
    学会使用 Mysql show processlist 排查问题
    Golang学习的方法和建议
    日志文件删除shell脚本
    运维趋势2019年总结,运维就是要做到"技多不压身"
    我的xshell配色方案,绿色/护眼/留存/备份
    对于api接口的爬虫,通常的解决方法
    maven 打包和构建的Linux命令(mvn)
    Istio的流量管理入门-charlieroro编写
  • 原文地址:https://www.cnblogs.com/priarieNew/p/9753922.html
Copyright © 2011-2022 走看看