procedure Form1.SetDriverComboBox;
const
Flags = SHCONTF_FOLDERS or SHCONTF_NONFOLDERS or SHCONTF_INCLUDEHIDDEN;
var
NewPIDL: PItemIDList;
DriveShellFolder: IShellFolder;
ID: PItemIDList;
EnumList: IEnumIDList;
NumIDs: LongWord;
SaveCursor: TCursor;
DispName : string;
begin
SaveCursor := Screen.Cursor;
try
Screen.Cursor := crHourglass;
OLECheck(
SHGetSpecialFolderLocation(
Application.Handle,
CSIDL_DRIVES,
NewPIDL)
);
OLECheck(
FIDesktopFolder.BindToObject(
NewPIDL,
nil,
IID_IShellFolder,
Pointer(DriveShellFolder))
);
OleCheck(
DriveShellFolder.EnumObjects(
Application.Handle,
Flags,
EnumList)
);
ComboBox.Items.Clear;
while EnumList.Next(1, ID, NumIDs) = S_OK do
begin
DispName := GetDisplayName(DriveShellFolder, ID, False);
if DispName = '控制面板' then Continue;
ComboBox.Items.Add(GetDisplayName(DriveShellFolder, ID, False));
end;
finally
Screen.Cursor := SaveCursor;
end;
end;