1. Introduction
BOOL SHGetSpecialFolderPath (
HWND hWndOwner,
LPTSTR Lpszpath,
int Nfolder,
BOOL fcreate
);
function:
Gets the specified system path.
Parameters:
HWND hWndOwner, a handle to the owner of the window. The GetDesktopWindow API can be used to fetch a window handle or to send null directly.
LPTSTR lpszpath, returns a buffer of the path that is at least the size of the MAX_PATH
int Nfolder, CSIDL identification of System path
BOOL fcreate that indicates whether the folder is created when it does not exist. False to not create, or create
CSIDL:
The CSIDL (constant special item ID list) is an ID listing of the system-defined special entries that are replaced by Knownfolderid after Vista (but CSIDL is still supported for compatibility). Defined in shlobj.h, as defined in the XP SDK:
#define CSIDL_DESKTOP 0x0000//<desktop>
#define Csidl_internet 0x0001//INTERNET Explorer (icon on desktop)
#define CSIDL_PROGRAMS 0x0002//Start Menu\Programs
#define Csidl_controls 0x0003//My Computer\control Panel
#define Csidl_printers 0x0004//My Computer\printers
#define CSIDL_PERSONAL 0x0005//My Documents
#define Csidl_favorites 0x0006//<user Name>\favorites
#define CSIDL_STARTUP 0x0007//Start Menu\Programs\Startup
#define Csidl_recent 0x0008//<user name>\recent
#define CSIDL_SENDTO 0x0009//<user Name>\sendto
#define Csidl_bitbucket 0x000a//<desktop>\recycle Bin
#define CSIDL_STARTMENU 0x000b//<user Name>\start Menu
#define Csidl_mydocuments csidl_personal//PERSONAL is just a silly name for my Documents
#define CSIDL_MYMUSIC 0x000d//"My Music" folder
#define CSIDL_MYVIDEO 0x000e//"My Videos" folder
#define Csidl_desktopdirectory 0x0010//<user Name>\desktop
#define Csidl_drives 0x0011//My Computer
#define CSIDL_NETWORK 0x0012//Network Neighborhood (My network Places)
#define Csidl_nethood 0x0013//<user Name>\nethood
#define Csidl_fonts 0x0014//Windows\Fonts
#define Csidl_templates 0x0015
#define CSIDL_COMMON_STARTMENU 0x0016//All Users\Start Menu
#define CSIDL_COMMON_PROGRAMS 0x0017//All Users\Start Menu\Programs
#define CSIDL_COMMON_STARTUP 0x0018//All Users\startup
#define Csidl_common_desktopdirectory 0x0019//All Users\Desktop
#define CSIDL_APPDATA 0x001a//<user name>\application Data
#define Csidl_printhood 0x001b//<user Name>\printhood
#ifndef Csidl_local_appdata
#define CSIDL_LOCAL_APPDATA 0x001c//<user name>\local Settings\applicaiton Data (non roaming)
#endif//Csidl_local_appdata
#define CSIDL_ALTSTARTUP 0x001d//Non localized startup
#define CSIDL_COMMON_ALTSTARTUP 0x001e//Non localized COMMON startup
#define Csidl_common_favorites 0x001f
#ifndef _shfolder_h_
#define Csidl_internet_cache 0x0020
#define Csidl_cookies 0x0021
#define Csidl_history 0x0022
#define CSIDL_COMMON_APPDATA 0x0023//All Users\Application Data
#define Csidl_windows 0x0024//GetWindowsDirectory ()
#define Csidl_system 0x0025//GetSystemDirectory ()
#define Csidl_program_files 0x0026//C:\Program FILES
#define CSIDL_MYPICTURES 0x0027//C:\Program files\my Pictures
#endif//_shfolder_h_
#define Csidl_profile 0x0028//UserProfile
#define CSIDL_SYSTEMX86 0x0029//x86 system directory on RISC
#define CSIDL_PROGRAM_FILESX86 0x002a//x86 C:\Program Files on RISC
#ifndef _shfolder_h_
#define Csidl_program_files_common 0x002b//C:\Program Files\Common
#endif//_shfolder_h_
#define CSIDL_PROGRAM_FILES_COMMONX86 0X002C//x86 Program Files\Common on RISC
#define Csidl_common_templates 0x002d//All Users\templates
#ifndef _shfolder_h_
#define csidl_common_documents 0x002e //All users\documents
#define csidl_common_admintools 0x002f //All Users\Start Menu \programs\administrative Tools
#define csidl_admintools 0x0030 //<user Name>\start Menu\Programs\Administrative Tools
#endif//_shfolder_h_
#define Csidl_connections 0x0031 //Network and dial-up connections
#define Csidl_common_ music 0x0035 //All users\my Music
#define csidl_common_pictures 0x0036 //All users\my Pictures
#define Csidl_ common_video 0x0037 /users\my Video
#define csidl_resources 0x0038 // Resource Direcotry
#ifndef _shfolder_h_
#define csidl_resources_localized 0x0039 //localized Resource direcotry
#endif//_shfolder_h_
#define csidl_common_oem_links 0x003a //Links to all Users OEM specific apps
#define Csidl_cdburn_area & nbsp; 0x003b // Userprofile\local Settings\Application Data\Microsoft\CD Burning
//unused 0x003c
#define csidl_computersnearme 0x003d //Computers Near Me (computered from Workgroup membership)
#ifndef _shfolder_h_
#define Csidl_flag_create 0x8000//combine with Csidl_ value to force folder creation in Shgetfolder Path ()
#endif//_shfolder_h_
#define CSIDL_FLAG_DONT_VERIFY 0x4000//combine with Csidl_ value to return an unverified folder path
#define 0X2000//combine with csidl_ value to avoid unexpanding csidl_flag_dont_unexpand environment Variab Les
#if (ntddi_version >= ntddi_winxp)
#define Csidl_flag_no_alias 0x1000//combine with Csidl_ value to insure Non-alias of the The PID L
#define CSIDL_FLAG_PER_USER_INIT 0x0800//combine with csidl_ value to indicate Per-user INIT (eg. upgrade)
#endif//NTDDI_WINXP
#define CSIDL_FLAG_MASK 0xff00//MASK for all possible FLAG values
return Value:
Returns true if the function succeeds, otherwise returns false
dependencies:
Header:shlobj.h
Import Library:shell32.lib
2, Example
#include <stdio.h>
#include <shlobj.h>
#pragma comment (lib, "Shell32.lib")
int _tmain (int argc, _tchar* argv[])
{
TCHAR Szpath[max_path];
BOOL Issuc = SHGetSpecialFolderPath (NULL, szpath, csidl_common_documents, FALSE);
if (ISSUC)
{
printf ("Get COMMON DOCUMENTS suceed." COMMON DOCUMENTS is:%s\r\n ", szpath);
}
Else
{
printf ("Get COMMON DOCUMENTS failed.\r\n");
}
return 0;
}