本文整理汇总了C#中SHFILEINFO.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# SHFILEINFO.GetType方法的具体用法?C# SHFILEINFO.GetType怎么用?C# SHFILEINFO.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SHFILEINFO
的用法示例。
在下文中一共展示了SHFILEINFO.GetType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetInfo
/// <summary>
/// Gets the information for the specified
/// file name and flags.
/// </summary>
public void GetInfo()
{
fileIcon = null;
typeName = "";
displayName = "";
SHFILEINFO shfi = new SHFILEINFO();
uint shfiSize = (uint)Marshal.SizeOf(shfi.GetType());
int ret = SHGetFileInfo(
fileName, 0, ref shfi, shfiSize, (uint)(flags));
if (ret != 0)
{
if (shfi.hIcon != IntPtr.Zero)
{
fileIcon = System.Drawing.Icon.FromHandle(shfi.hIcon);
// Now owned by the GDI+ object
//DestroyIcon(shfi.hIcon);
}
typeName = shfi.szTypeName;
displayName = shfi.szDisplayName;
}
else
{
int err = GetLastError();
Console.WriteLine("Error {0}", err);
string txtS = new string('\0', 256);
int len = FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
IntPtr.Zero, err, 0, txtS, 256, 0);
Console.WriteLine("Len {0} text {1}", len, txtS);
// throw exception
}
}
示例2: create
/// <summary>
/// Creates the SystemImageList
/// </summary>
private void create()
{
// forget last image list if any:
hIml = IntPtr.Zero;
if (isXpOrAbove())
{
// Get the System IImageList object from the Shell:
Guid iidImageList = new Guid("46EB5926-582E-4017-9FDF-E8998DAA0950");
int ret = SHGetImageList(
(int)size,
ref iidImageList,
ref iImageList
);
// the image list handle is the IUnknown pointer, but
// using Marshal.GetIUnknownForObject doesn't return
// the right value. It really doesn't hurt to make
// a second call to get the handle:
SHGetImageListHandle((int)size, ref iidImageList, ref hIml);
}
else
{
// Prepare flags:
SHGetFileInfoConstants dwFlags = SHGetFileInfoConstants.SHGFI_USEFILEATTRIBUTES | SHGetFileInfoConstants.SHGFI_SYSICONINDEX;
if (size == SysImageListSize.smallIcons)
{
dwFlags |= SHGetFileInfoConstants.SHGFI_SMALLICON;
}
// Get image list
SHFILEINFO shfi = new SHFILEINFO();
uint shfiSize = (uint)Marshal.SizeOf(shfi.GetType());
// Call SHGetFileInfo to get the image list handle
// using an arbitrary file:
hIml = SHGetFileInfo(
".txt",
FILE_ATTRIBUTE_NORMAL,
ref shfi,
shfiSize,
(uint)dwFlags);
System.Diagnostics.Debug.Assert((hIml != IntPtr.Zero), "Failed to create Image List");
}
}
示例3: IconIndex
/// <summary>
/// Returns the index of the icon for the specified file
/// </summary>
/// <param name="fileName">Filename to get icon for</param>
/// <param name="forceLoadFromDisk">If True, then hit the disk to get the icon,
/// otherwise only hit the disk if no cached icon is available.</param>
/// <param name="iconState">Flags specifying the state of the icon
/// returned.</param>
/// <returns>Index of the icon</returns>
public int IconIndex(
string fileName,
bool forceLoadFromDisk,
ShellIconStateConstants iconState
)
{
SHGetFileInfoConstants dwFlags = SHGetFileInfoConstants.SHGFI_SYSICONINDEX;
int dwAttr = 0;
if (size == SysImageListSize.smallIcons)
{
dwFlags |= SHGetFileInfoConstants.SHGFI_SMALLICON;
}
// We can choose whether to access the disk or not. If you don't
// hit the disk, you may get the wrong icon if the icon is
// not cached. Also only works for files.
if (!forceLoadFromDisk)
{
dwFlags |= SHGetFileInfoConstants.SHGFI_USEFILEATTRIBUTES;
dwAttr = FILE_ATTRIBUTE_NORMAL;
}
else
{
dwAttr = 0;
}
// sFileSpec can be any file. You can specify a
// file that does not exist and still get the
// icon, for example sFileSpec = "C:\PANTS.DOC"
SHFILEINFO shfi = new SHFILEINFO();
uint shfiSize = (uint)Marshal.SizeOf(shfi.GetType());
IntPtr retVal = SHGetFileInfo(
fileName, dwAttr, ref shfi, shfiSize,
((uint)(dwFlags) | (uint)iconState));
if (retVal.Equals(IntPtr.Zero))
{
System.Diagnostics.Debug.Assert((!retVal.Equals(IntPtr.Zero)), "Failed to get icon index");
return 0;
}
else
{
return shfi.iIcon;
}
}
示例4: GetInfo
public void GetInfo() {
ShellIcon = null;
TypeName = string.Empty;
DisplayName = string.Empty;
var shfi = new SHFILEINFO();
var shfiSize = (uint) Marshal.SizeOf(shfi.GetType());
var ret = SHGetFileInfo(
FileName, 0, ref shfi, shfiSize, (uint) Flags);
if (ret != 0) {
if (shfi.hIcon != IntPtr.Zero) {
ShellIcon = Icon.FromHandle(shfi.hIcon);
// Now owned by the GDI+ object
//DestroyIcon(shfi.hIcon);
}
TypeName = shfi.szTypeName;
DisplayName = shfi.szDisplayName;
} else {
var err = GetLastError();
Console.WriteLine("Error {0}", err);
var txtS = new string('\0', 256);
var len = FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
IntPtr.Zero, err, 0, txtS, 256, 0);
Console.WriteLine("Len {0} text {1}", len, txtS);
// throw exception
}
}
示例5: IconIndex
/// <summary>
/// Returns the index of the icon for the specified file
/// </summary>
/// <param name = "fileName">Filename to get icon for</param>
/// <param name = "forceLoadFromDisk">If True, then hit the disk to get the icon,
/// otherwise only hit the disk if no cached icon is available.</param>
/// <param name = "iconState">Flags specifying the state of the icon
/// returned.</param>
/// <returns>Index of the icon</returns>
public int IconIndex(
string fileName,
bool forceLoadFromDisk,
ShellIconStateConstants iconState
)
{
SHGetFileInfoConstants dwFlags = SHGetFileInfoConstants.SHGFI_SYSICONINDEX |
SHGetFileInfoConstants.SHGFI_DISPLAYNAME | SHGetFileInfoConstants.SHGFI_TYPENAME;
int dwAttr = 0;
if (size == SystemImageListSize.SmallIcons)
{
dwFlags |= SHGetFileInfoConstants.SHGFI_SMALLICON;
}
// We can choose whether to access the disk or not. If you don't
// hit the disk, you may get the wrong icon if the icon is
// not cached. Also only works for files.
if (!forceLoadFromDisk)
{
dwFlags |= SHGetFileInfoConstants.SHGFI_USEFILEATTRIBUTES;
dwAttr = FILE_ATTRIBUTE_NORMAL;
}
else
{
dwAttr = 0;
}
// sFileSpec can be any file. You can specify a
// file that does not exist and still get the
// icon, for example sFileSpec = "C:\PANTS.DOC"
SHFILEINFO shfi = new SHFILEINFO();
uint shfiSize = (uint)Marshal.SizeOf(shfi.GetType());
IntPtr retVal = SHGetFileInfo(
fileName, dwAttr, ref shfi, shfiSize,
((uint)(dwFlags) | (uint)iconState));
if (retVal == IntPtr.Zero)
{
// Seems to be a special folder, so we need to try with the PIDL
dwFlags |= SHGetFileInfoConstants.SHGFI_PIDL;
IntPtr pidl = IntPtr.Zero;
uint iAttribute;
// Convert the folder name to the PIDL and get it's icon
SHParseDisplayName(fileName, IntPtr.Zero, out pidl, 0, out iAttribute);
if (pidl == IntPtr.Zero)
{
return 0;
}
retVal = SHGetFileInfo(pidl, dwAttr, ref shfi, shfiSize, ((uint)(dwFlags) | (uint)iconState));
Marshal.FreeCoTaskMem(pidl);
if (retVal != IntPtr.Zero)
{
return shfi.iIcon;
}
return 0;
}
return shfi.iIcon;
}
示例6: GetInfo
public void GetInfo()
{
ShellIcon = null;
TypeName = "";
DisplayName = "";
var shfi = new SHFILEINFO();
var shfiSize = (uint)Marshal.SizeOf(shfi.GetType());
var ret = NativeMethods.SHGetFileInfo(
FileName, 0, ref shfi, shfiSize, (uint)(Flags));
if (ret != (IntPtr) 0)
{
if (shfi.hIcon != IntPtr.Zero)
{
ShellIcon = Icon.FromHandle(shfi.hIcon);
}
TypeName = shfi.szTypeName;
DisplayName = shfi.szDisplayName;
}
else
{
var err = NativeMethods.GetLastError();
Console.WriteLine("Error {0}", err);
var txtS = new string('\0', 256);
var len = NativeMethods.FormatMessage(
FormatMessageFromSystem | FormatMessageIgnoreInserts,
IntPtr.Zero, err, 0, txtS, 256, (IntPtr)0);
Console.WriteLine("Len {0} text {1}", len, txtS);
}
}