作者:暖倪2502938803 | 来源:互联网 | 2023-09-23 19:51
本例效果图:代码文件:unitUnit1;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Cont
本例效果图:
代码文件:
unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTForm1 = class(TForm)Memo1: TMemo;procedure FormCreate(Sender: TObject);end;varForm1: TForm1;implementation{$R *.dfm}uses ShlObj; {SHGetSpecialFolderLocation、SHGetPathFromIDList 函数来自这个单元}{获取常用路径的函数}
function GetPath(FID: Integer): string;
varpidl: PItemIDList;path: array[0..MAX_PATH] of Char;
beginSHGetSpecialFolderLocation(0, FID, pidl);SHGetPathFromIDList(pidl, path);Result := path;
end;{测试时, 我把 SHGetSpecialFolderLocation 函数需要的参数定义成了一个常数数组}
constarr: array[0..57] of Integer = (CSIDL_DESKTOP , { = $0000 }CSIDL_INTERNET , { = $0001 }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_BITBUCKET , { = $000a }CSIDL_STARTMENU , { = $000b }CSIDL_MYDOCUMENTS , { = $000c }CSIDL_MYMUSIC , { = $000d }CSIDL_MYVIDEO , { = $000e }CSIDL_DESKTOPDIRECTORY , { = $0010 }CSIDL_DRIVES , { = $0011 }CSIDL_NETWORK , { = $0012 }CSIDL_NETHOOD , { = $0013 }CSIDL_FONTS , { = $0014 }CSIDL_TEMPLATES , { = $0015 }CSIDL_COMMON_STARTMENU , { = $0016 }CSIDL_COMMON_PROGRAMS , { = $0017 }CSIDL_COMMON_STARTUP , { = $0018 }CSIDL_COMMON_DESKTOPDIRECTORY , { = $0019 }CSIDL_APPDATA , { = $001a }CSIDL_PRINTHOOD , { = $001b }CSIDL_LOCAL_APPDATA , { = $001c }CSIDL_ALTSTARTUP , { = $001d }CSIDL_COMMON_ALTSTARTUP , { = $001e }CSIDL_COMMON_FAVORITES , { = $001f }CSIDL_INTERNET_CACHE , { = $0020 }CSIDL_COOKIES , { = $0021 }CSIDL_HISTORY , { = $0022 }CSIDL_COMMON_APPDATA , { = $0023 }CSIDL_WINDOWS , { = $0024 }CSIDL_SYSTEM , { = $0025 }CSIDL_PROGRAM_FILES , { = $0026 }CSIDL_MYPICTURES , { = $0027 }CSIDL_PROFILE , { = $0028 }CSIDL_SYSTEMX86 , { = $0029 }CSIDL_PROGRAM_FILESX86 , { = $002a }CSIDL_PROGRAM_FILES_COMMON , { = $002b }CSIDL_PROGRAM_FILES_COMMONX86 , { = $002c }CSIDL_COMMON_TEMPLATES , { = $002d }CSIDL_COMMON_DOCUMENTS , { = $002e }CSIDL_COMMON_ADMINTOOLS , { = $002f }CSIDL_ADMINTOOLS , { = $0030 }CSIDL_CONNECTIONS , { = $0031 }CSIDL_COMMON_MUSIC , { = $0035 }CSIDL_COMMON_PICTURES , { = $0036 }CSIDL_COMMON_VIDEO , { = $0037 }CSIDL_RESOURCES , { = $0038 }CSIDL_RESOURCES_LOCALIZED , { = $0039 }CSIDL_COMMON_OEM_LINKS , { = $003a }CSIDL_CDBURN_AREA , { = $003b }CSIDL_COMPUTERSNEARME , { = $003d }CSIDL_PROFILES { = $003e });{测试}
procedure TForm1.FormCreate(Sender: TObject);
vari: Integer;s: string;
beginMemo1.Clear;for i :&#61; 0 to Length(Arr) - 1 dobegins :&#61; GetPath(Arr[i]);if s<>&#39;&#39; then Memo1.Lines.Add(Format(&#39;%d:&#39;#9&#39;%s&#39;, [Arr[i], s]));end;
end;end.
窗体文件:
object Form1: TForm1Left &#61; 0Top &#61; 0Caption &#61; &#39;Form1&#39;ClientHeight &#61; 318ClientWidth &#61; 465Color &#61; clBtnFaceFont.Charset &#61; DEFAULT_CHARSETFont.Color &#61; clWindowTextFont.Height &#61; -11Font.Name &#61; &#39;Tahoma&#39;Font.Style &#61; []OldCreateOrder &#61; FalseOnCreate &#61; FormCreatePixelsPerInch &#61; 96TextHeight &#61; 13object Memo1: TMemoLeft &#61; 0Top &#61; 0Width &#61; 465Height &#61; 318Align &#61; alClientLines.Strings &#61; (&#39;Memo1&#39;)ScrollBars &#61; ssBothTabOrder &#61; 0ExplicitWidth &#61; 409end
end