在Windows 7的文件夾圖標,我有以下代碼在Windows XP和Vista的作品 - 無論是32位和64位:如何抓使用Shell32.SHGetFileInfo
public static Icon GetFolderIcon(IconSize size, FolderType folderType)
{
// Need to add size check, although errors generated at present!
uint flags = Shell32.SHGFI_ICON | Shell32.SHGFI_USEFILEATTRIBUTES;
if (FolderType.Open == folderType)
{
flags += Shell32.SHGFI_OPENICON;
}
if (IconSize.Small == size)
{
flags += Shell32.SHGFI_SMALLICON;
}
else
{
flags += Shell32.SHGFI_LARGEICON;
}
// Get the folder icon
var shfi = new Shell32.SHFILEINFO();
Shell32.SHGetFileInfo( null,
Shell32.FILE_ATTRIBUTE_DIRECTORY,
ref shfi,
(uint) Marshal.SizeOf(shfi),
flags);
Icon.FromHandle(shfi.hIcon); // Load the icon from an HICON handle
// Now clone the icon, so that it can be successfully stored in an ImageList
var icon = (Icon)Icon.FromHandle(shfi.hIcon).Clone();
User32Dll.DestroyIcon(shfi.hIcon); // Cleanup
return icon;
}
的常量的定義方式如下:
public const uint SHGFI_ICON = 0x000000100;
public const uint SHGFI_USEFILEATTRIBUTES = 0x000000010;
public const uint SHGFI_OPENICON = 0x000000002;
public const uint SHGFI_SMALLICON = 0x000000001;
public const uint SHGFI_LARGEICON = 0x000000000;
public const uint FILE_ATTRIBUTE_DIRECTORY = 0x00000010;
此獲取的文件夾圖標時,給出了在Windows 7下面的結果
雖然在Vista中 - 使用下面的文件夾圖標相同的方法結果:
我想「正確的」 Windows文件夾中的Windows 7圖標也 - 不是用來指示驅動器的圖標在哪裏安裝Windows。
我不知道win32 API,而我的非託管編程在Windows平臺上幾乎沒有。
請澄清你的問題。「這會導致帶有以下圖標的Windows 7」是什麼意思? – 2009-10-21 07:27:40