码迷,mamicode.com
首页 > Windows程序 > 详细

Windows API 第二篇 SHGetSpecialFolderPath

时间:2018-10-08 15:03:22      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:dia   pre   folder   jpg   lob   pts   display   mon   ati   

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"\r\n");

    bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_PROGRAM_FILES_COMMON, FALSE);
    strMsgW.append(L"CSIDL_PROGRAM_FILES_COMMON: ");
    strMsgW.append(szPath);
    strMsgW.append(L"\r\n");

    bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_SYSTEM, FALSE);
    strMsgW.append(L"CSIDL_SYSTEM: ");
    strMsgW.append(szPath);
    strMsgW.append(L"\r\n");

    bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_STARTUP , FALSE);
    strMsgW.append(L"CSIDL_STARTUP: ");
    strMsgW.append(szPath);
    strMsgW.append(L"\r\n");

    bRet = SHGetSpecialFolderPath(NULL, szPath, CSIDL_APPDATA , FALSE);
    strMsgW.append(L"CSIDL_APPDATA: ");
    strMsgW.append(szPath);
    strMsgW.append(L"\r\n");

    MessageBox(NULL, strMsgW.c_str(), L"SHGetSpecialFolderPath Test", MB_OK);

    return 0;
}

运行结果:

 

技术分享图片

 

Windows API 第二篇 SHGetSpecialFolderPath

标签:dia   pre   folder   jpg   lob   pts   display   mon   ati   

原文地址:https://www.cnblogs.com/priarieNew/p/9753922.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!