(SHGetSpecialFolderLocation,SHGetPathFromIDList) 都是API函数 -------------------- 哈哈哈哈哈哈哈哈哈哈Retrieves the location of a special folder.WINSHELLAPI HRESULT WINAPI SHGetSpecialFolderLocation(; HWND hwndOwner, int nFolder, LPITEMIDLIST *ppidl ); ParametershwndOwnerHandle of the owner window that the client should specify if it displays a dialog box or message box.nFolderValue specifying the folder to retrieve the location of. This parameter can be one of the following values:CSIDL_BITBUCKET Recycle bin ?file system directory containing file objects in the user's recycle bin. The location of this directory is not in the registry; it is ed with the hidden and system attributes to prevent the user from moving or deleting it. CSIDL_CONTROLS Control Panel ?virtual folder containing icons for the control panel applications. CSIDL_DESKTOP Windows desktop ?virtual folder at the root of the name space. 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 ?virtual folder containing everything on the local computer: storage devices, printers, and Control Panel. The folder may also contain mapped network drives. CSIDL_FONTS Virtual folder containing fonts. CSIDL_NETHOOD File system directory containing objects that appear in the network neighborhood. CSIDL_NETWORK Network Neighborhood ?virtual folder representing the top level of the network hierarchy. CSIDL_PERSONAL File system directory that serves as a common respository for documents. CSIDL_PRINTERS Printers folder ?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. CSIDL_TEMPLATES File system directory that serves as a common repository for document templates. ppidlAddress that receives a pointer to an item identifier list specifying the folder's location relative to the root of the name space (the desktop). Return ValuesReturns NOERROR if successful or an OLE-defined error result otherwise.
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls,registry;type
TForm1 = class(TForm)
Panel1: TPanel;
StaticText1: TStaticText;
StaticText2: TStaticText;
StaticText3: TStaticText;
StaticText4: TStaticText;
StaticText5: TStaticText;
StaticText6: TStaticText;
StaticText7: TStaticText;
StaticText8: TStaticText;
StaticText9: TStaticText;
StaticText10: TStaticText;
StaticText11: TStaticText;
StaticText12: TStaticText;
StaticText13: TStaticText;
StaticText14: TStaticText;
StaticText15: TStaticText;
StaticText16: TStaticText;
StaticText17: TStaticText;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Edit8: TEdit;
Edit9: TEdit;
Edit10: TEdit;
Edit11: TEdit;
Edit12: TEdit;
Edit13: TEdit;
Edit14: TEdit;
Edit15: TEdit;
Edit16: TEdit;
Edit17: TEdit;
Edit18: TEdit;
Edit19: TEdit;
Edit20: TEdit;
StaticText18: TStaticText;
StaticText19: TStaticText;
StaticText20: TStaticText;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}const
cShellAppData = 'AppData';
cShellCache = 'Cache';
cShellCookies = 'Cookies';
cShellDesktop = 'Desktop';
cShellFavorites = 'Favorites';
cShellFonts = 'Fonts';
cShellHistory = 'History';
cShellLocalApp = 'Local AppData';
cShellNetHood = 'NetHood';
cShellPersonal = 'Personal';
cShellPrintHood = 'PrintHood';
cShellPrograms = 'Programs';
cShellRecent = 'Recent';
cShellSendTo = 'SendTo';
cShellStartMenu = 'Start Menu';
CShellStartUp = 'Startup';
cShellTemplates = 'Templates';
cShellAdmTools = 'Administrative Tools';
cShellLocalSet = 'Local Settings';
cShellMyPic = 'My Pictures';
//定义若干常量function GetShellFolder (const folder: string):string;
const
cWin32='SOFTWARE\Microsoft\Windows\CurrentVersion';
cSHellPrefix = '\Explorer\Shell Folders';
var
r:TRegistry;
begin
Result:='';
r:=TRegistry.Create;
//创建对象
try
r.Rootkey:=HKEY_CURRENT_USER;
//只要是Windows95及其以后版本,此处都一样
if r.OpenKey (cWin32 + cShellPrefix, False) then
//打开键,开始读取
Result:= r.ReadString (folder) + '\';
finally
r.Free;
//释放创建的对象
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text:=GetShellFolder(cShellAppData);
Edit2.Text:=GetShellFolder(cShellCache);
Edit3.Text:=GetShellFolder(cShellCookies);
Edit4.Text:=GetShellFolder(cShellDesktop);
Edit5.Text:=GetShellFolder(cShellFavorites);
Edit6.Text:=GetShellFolder(cShellFonts);
Edit7.Text:=GetShellFolder(cShellHistory);
Edit8.Text:=GetShellFolder(cShellLocalApp);
Edit9.Text:=GetShellFolder(cShellNetHood);
Edit10.Text:=GetShellFolder(cShellPersonal);
Edit11.Text:=GetShellFolder(cShellPrintHood);
Edit12.Text:=GetShellFolder(cShellPrograms);
Edit13.Text:=GetShellFolder(cShellRecent);
Edit14.Text:=GetShellFolder(cShellSendTo);
Edit15.Text:=GetShellFolder(cShellStartMenu);
Edit16.Text:=GetShellFolder(CShellStartUp);
Edit17.Text:=GetShellFolder(cShellTemplates);
Edit18.Text:=GetShellFolder(cShellAdmTools);
Edit19.Text:=GetShellFolder(cShellLocalSet);
Edit20.Text:=GetShellFolder(cShellMyPic);
end;
end.
另一种方法是调用shell函数可以得到相应的目录,但是不是所有在shell folder目录下的文件夹都可以获得,请注意。function GetSpecialFolderDir(const folderid:integer):string;varpidl:pItemIDList;buffer:array [ 0..255 ] of char ;begin//取指定的文件夹项目表SHGetSpecialFolderLocation( application.Handle , folderid, pidl);SHGetPathFromIDList(pidl, buffer); //转换成文件系统的路径result:=strpas(buffer);end;其中:folderid可以取下面的值:但是请注意,有些是虚的文件夹,不是文件系统的一部分,所以用SHGetPathFromIDList是取不出路径的,但是在此也列出了。打'*'号的为不是真正的文件系统,应该用作它用。CSIDL_BITBUCKET * 回收站CSIDL_CONTROLS * 控制面板CSIDL_DESKTOP * 桌面CSIDL_DESKTOPDIRECTORY 桌面目录 //如C:CSIDL_DRIVES * 我的电脑CSIDL_FONTS 字体 //如C:CSIDL_NETHOOD 网上邻居目录 //如C:CSIDL_NETWORK * 网上邻居CSIDL_PERSONAL 我的文档 //如C:DocumentsCSIDL_PRINTERS * 打印机CSIDL_PROGRAMS 程序组 //如C:MenuCSIDL_RECENT 最近文档 //如C:CSIDL_SENDTO 发送到 //如C:CSIDL_STARTMENU 开始菜单 //如C:MenuCSIDL_STARTUP 启动 //如C:\u21551启动CSIDL_TEMPLATES 模版 //如C:
---------------------------------------------------------------------------
可是这里面的函数(SHGetSpecialFolderLocation,SHGetPathFromIDList)在哪个包里面啊,晕死了啊!
都是API函数
--------------------
哈哈哈哈哈哈哈哈哈哈Retrieves the location of a special folder.WINSHELLAPI HRESULT WINAPI SHGetSpecialFolderLocation(; HWND hwndOwner,
int nFolder,
LPITEMIDLIST *ppidl
);
ParametershwndOwnerHandle of the owner window that the client should specify if it displays a dialog box or message box.nFolderValue specifying the folder to retrieve the location of. This parameter can be one of the following values:CSIDL_BITBUCKET Recycle bin ?file system directory containing file objects in the user's recycle bin. The location of this directory is not in the registry; it is ed with the hidden and system attributes to prevent the user from moving or deleting it.
CSIDL_CONTROLS Control Panel ?virtual folder containing icons for the control panel applications.
CSIDL_DESKTOP Windows desktop ?virtual folder at the root of the name space.
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 ?virtual folder containing everything on the local computer: storage devices, printers, and Control Panel. The folder may also contain mapped network drives.
CSIDL_FONTS Virtual folder containing fonts.
CSIDL_NETHOOD File system directory containing objects that appear in the network neighborhood.
CSIDL_NETWORK Network Neighborhood ?virtual folder representing the top level of the network hierarchy.
CSIDL_PERSONAL File system directory that serves as a common respository for documents.
CSIDL_PRINTERS Printers folder ?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.
CSIDL_TEMPLATES File system directory that serves as a common repository for document templates.
ppidlAddress that receives a pointer to an item identifier list specifying the folder's location relative to the root of the name space (the desktop). Return ValuesReturns NOERROR if successful or an OLE-defined error result otherwise.
const
CSIDL_DESKTOP = $0000;
CSIDL_PROGRAMS = $0002;
CSIDL_CONTROLS = $0003;
CSIDL_PRINTERS = $0004;
CSIDL_PERSONAL = $0005;
CSIDL_FAVORITES = $0006;
CSIDL_STARTUP = $0007;
CSIDL_RECENT = $0008;
CSIDL_SENDTO = $0009;
CSIDL_STARTMENU = $000b;
CSIDL_DESKTOPDIRECTORY = $0010;
CSIDL_FONTS = $0014;
CSIDL_TEMPLATES = $0015;
CSIDL_COMMON_STARTMENU = $0016;
CSIDL_COMMON_PROGRAMS = $0017;
CSIDL_COMMON_STARTUP = $0018;
CSIDL_COMMON_DESKTOPDIRECTORY = $0019;function GetFontPath:string;
var
Path: array[0..MAX_PATH] of char;
begin
SHGetSpecialFolderPath(0,Path,CSIDL_FONTS,True);
result := Path;
end;
C:\Program Files\Borland\Delphi7\Demos\Virtual Listview