SHGetSpecialFolderPath 获取系统预设的目录

博客介绍了如何使用SHGetSpecialFolderPath函数动态获取Program Files路径,特别是在64位系统中,即使程序是32位的,也能正确指向C:\Program Files (x86)。
摘要由CSDN通过智能技术生成

比较实用的就是获取Program Files的目录,这个目录当系统装在不同的盘下,或者64位系统下都会不同,hard code是最差的办法了。

使用CSIDL_PROGRAM_FILES参数动态获取这个路径。

特别地,CSIDL_PROGRAM_FILES,在64位系统下面,如果你的程序是32位的,这个参数仍然会定位到C:\Program Files (x86)

http://msdn.microsoft.com/en-us/library/bb762204%28v=VS.85%29.aspx

Syntax

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

Parameters

hwndOwner
A handle to the owner window that the client should specify if it displays a dialog box or message box.
lpszPath
A pointer 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 whether 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.

Return Value

Returns TRUE if successful, or FALSE otherwise.


CSIDL_ADMINTOOLS (FOLDERID_AdminTools)
Version 5.0. The file system directory that is used to store administrative tools for an individual user. The Microsoft Management Console (MMC) will save customized consoles to this directory, and it will roam with the user.
CSIDL_ALTSTARTUP (FOLDERID_Startup)
The file system directory that corresponds to the user's nonlocalized Startup program group. This value is recognized in Windows Vista for backward compatibility, but the folder itself no longer exists.
CSIDL_APPDATA (FOLDERID_RoamingAppData)
Version 4.71. The file system directory that serves as a common repository for application-specific data. A typical path is C:\Documents and Settings\ username\Application Data. This CSIDL is supported by the redistributable Shfolder.dll for systems that do not have the Microsoft Internet Explorer 4.0 integrated Shell installed.
CSIDL_BITBUCKET (FOLDERID_RecycleBinFolder)
The virtual folder that contains the objects in the user's Recycle Bin.
CSIDL_CDBURN_AREA (FOLDERID_CDBurning)
Version 6.0. The file system directory that acts as a staging area for files waiting to be written to a CD. A typical path is C:\Documents and Settings\ username\Local Settings\Application Data\Microsoft\CD Burning.
CSIDL_COMMON_ADMINTOOLS (FOLDERID_CommonAdminTools)
Version 5.0. The file system directory that contains administrative tools for all users of the computer.
CSIDL_COMMON_ALTSTARTUP (FOLDERID_CommonStartup)
The file system directory that
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值