tools/Stampfer/PeterSource1_1/Classes/cCommon.cs
/// <summary>
/// Gets the Shell Icon for the given file...
/// </summary>
/// <param name="name">Path to file.</param>
/// <param name="linkOverlay">Shortcut Overlay or not</param>
/// <returns>Icon</returns>
Gets the Shell Icon for the given file
Gets the Shell Icon for the given file
public static System.Drawing.Icon GetFileIcon(string name, bool linkOverlay)
        {
            cShell32.SHFILEINFO shfi = new cShell32.SHFILEINFO();
            uint flags = cShell32.SHGFI_ICON | cShell32.SHGFI_USEFILEATTRIBUTES;
            if (linkOverlay) flags += cShell32.SHGFI_LINKOVERLAY;
            cShell32.SHGetFileInfo(name,
                                  cShell32.FILE_ATTRIBUTE_NORMAL,
                                  ref shfi,
                                  (uint)System.Runtime.InteropServices.Marshal.SizeOf(shfi),
                                  flags);
            try
            {
                System.Drawing.Icon icon = (System.Drawing.Icon)System.Drawing.Icon.FromHandle(shfi.hIcon).Clone();
                User32.DestroyIcon(shfi.hIcon); 
                return icon;
            }
            catch { return null; }
        }
public static System . Drawing . Icon GetFileIcon ( string name , bool linkOverlay ) { cShell32 . SHFILEINFO shfi = new cShell32 . SHFILEINFO ( ) ; uint flags = cShell32 . SHGFI_ICON | cShell32 . SHGFI_USEFILEATTRIBUTES ; if ( linkOverlay ) flags += cShell32 . SHGFI_LINKOVERLAY ; cShell32 . SHGetFileInfo ( name , cShell32 . FILE_ATTRIBUTE_NORMAL , ref shfi , ( uint ) System . Runtime . InteropServices . Marshal . SizeOf ( shfi ) , flags ) ; try { System . Drawing . Icon icon = ( System . Drawing . Icon ) System . Drawing . Icon . FromHandle ( shfi . hIcon ) . Clone ( ) ; User32 . DestroyIcon ( shfi . hIcon ) ; return icon ; } catch { return null ; } }
Gets the Shell Icon for the given file...
Gets the Shell Icon for the given file ...
// flags += cShell32.SHGFI_SMALLICON; // include the small icon flag // Copy (clone) the returned icon to a new object, thus allowing us  // to call DestroyIcon immediately // Cleanup
None
name
string
Path to file.
Path to file .
linkOverlay
bool
Shortcut Overlay or not
Shortcut Overlay or not