SHGetSpecialFolderLocation();怎么使用??SHGetSpecialFolderLocation();怎么使用??SHGetSpecialFolderLocation();怎么使用??

BCBird 2001-09-21 08:06:01
加精
SHGetSpecialFolderLocation
This function retrieves the location of a special folder, such as My Handheld PC, Recycle Bin, Control Panel, Desktop, Printers, Fonts, or various file system directories.

WINSHELLAPI HRESULT WINAPI SHGetSpecialFolderLocation(
HWND hwndOwner,
int nFolder,
LPITEMIDLIST *ppidl );
Parameters
hwndOwner
[in] Handle to the owner window the client should specify if it displays a dialog box or message box.
nFolder
[in] Value specifying the folder for which to retrieve the location. It is one of the following values:
Value Description
CSIDL_BITBUCKET File system directory that contains file objects in the user's Recycle Bin. The location of this directory is not in the registry; it is marked with the hidden and system attributes to prevent the user from moving or deleting it.
CSIDL_CONTROLS Virtual folder containing icons for the Control Panel applications.
CSIDL_DESKTOP Windows Desktop, which is a virtual folder at the root of the namespace.
CSIDL_DESKTOPDIRECTORY File system directory used to physically store file objects on the desktop (not to be confused with the desktop folder itself).
CSIDL_DRIVES My Computer, which is a virtual folder that contains everything on the local computer: storage devices, printers, and Control Panel. The folder may also contain mapped network drives.
CSIDL_FAVORITES File system directory that serves as a common repository for the user's favorite items.
CSIDL_FONTS Virtual folder containing fonts.
CSIDL_NETHOOD File system directory containing objects that appear in the network neighborhood.
CSIDL_NETWORK Network Neighborhood Folder, which is a virtual folder that represents the top level of the network hierarchy.
CSIDL_PERSONAL File system directory that serves as a common repository for documents.
CSIDL_PRINTERS Virtual folder containing installed printers.
CSIDL_PROGRAMS File system directory that contains the user's program groups (which are also file system directories).
CSIDL_RECENT File system directory that contains the user's most recently used documents.
CSIDL_SENDTO File system directory that contains Send To menu items.
CSIDL_STARTMENU File system directory containing Start menu items.
CSIDL_STARTUP File system directory that corresponds to the user's Startup program group. The system starts these programs when a device is powered on.
CSIDL_TEMPLATES File system directory that serves as a common repository for document templates.




ppidl
[in] Pointer to a pointer to an item identifier list specifying the folder's location relative to the root of the namespace (the desktop). The calling application is responsible for freeing this pointer with the shell's IMalloc interface (see SHGetMalloc).
Return Values
NOERROR indicates success. An OLE-defined error result indicates failure.

Requirements

Runs on Versions Defined in Include Link to
Windows CE OS 1.0 and 2.12 Shlobj.h



Note This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.

Built on Thursday, November 16, 2000
--------------------------------------------------------------------------------

如何实现:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
Edit1->Text=Favorites文件夹的具体路径;
}
//---------------------------------------------------------------------------

...全文
486 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
BCBird 2001-09-22
  • 打赏
  • 举报
回复
是啊,给分了。
wilddragon 2001-09-21
  • 打赏
  • 举报
回复
值得注意
ttzzgg_80713 2001-09-21
  • 打赏
  • 举报
回复
同上
xycleo 2001-09-21
  • 打赏
  • 举报
回复
上面的弟兄说得对1!
CTO 2001-09-21
  • 打赏
  • 举报
回复

不仅要加上头文件,在.cpp的第一行,加上 #define NO_WIN32_LEAN_AND_MEAN

然后再 #include "shlobj.h",否则不能用,在shlobj.h出现重复定义的错误!


sundayboys 2001-09-21
  • 打赏
  • 举报
回复
头文件你不加上嘛?你给的定义上都说 了阿
BCBird 2001-09-21
  • 打赏
  • 举报
回复

谢谢,编译出错:

[C++ Error] Unit1.cpp(21): E2451 Undefined symbol 'LPITEMIDLIST'
[C++ Error] Unit1.cpp(21): E2379 Statement missing ;
[C++ Error] Unit1.cpp(25): E2268 Call to undefined function 'SHGetMalloc'
[C++ Error] Unit1.cpp(29): E2268 Call to undefined function 'SHGetSpecialFolderLocation'
[C++ Error] Unit1.cpp(29): E2451 Undefined symbol 'CSIDL_FAVORITES'
[C++ Error] Unit1.cpp(29): E2451 Undefined symbol 'pidl'
[C++ Error] Unit1.cpp(32): E2268 Call to undefined function 'SHGetPathFromIDList'


如何实现:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
Edit1->Text=Favorites文件夹的具体路径;
}
//---------------------------------------------------------------------------




sundayboys 2001-09-21
  • 打赏
  • 举报
回复
下面的代码演示了怎样使用SHGetSpecialFolderLocation:

//----------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
LPITEMIDLIST pidl;
LPMALLOC pShellMalloc;
char szDir[MAX_PATH];

if(SUCCEEDED(SHGetMalloc(&pShellMalloc)))
{
if(SUCCEEDED(SHGetSpecialFolderLocation(NULL,
CSIDL_FAVORITES,
&pidl)))
{
// 如果成功返回true
if(SHGetPathFromIDList(pidl, szDir))
{
Label1->Caption = szDir;
}

pShellMalloc->Free(pidl);
}

pShellMalloc->Release();
}
}
//----------------------------------------------------------------------
Jneu 2001-09-21
  • 打赏
  • 举报
回复
up
BCBird 2001-09-21
  • 打赏
  • 举报
回复
up

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧