2011-07-29 8 views

답변

10

는이 코드를 DLL에서 아이콘을 추출 할 수 있습니다 응용 프로그램에서 재배포를 라이센스에 대한 마이크로 소프트의 변호사에게 이야기해야 할 것 :

당신은 DLL에있는 이미지의 인덱스를 알 필요가 물론
public class IconExtractor 
{ 

    public static Icon Extract(string file, int number, bool largeIcon) 
    { 
     IntPtr large; 
     IntPtr small; 
     ExtractIconEx(file, number, out large, out small, 1); 
     try 
     { 
      return Icon.FromHandle(largeIcon ? large : small); 
     } 
     catch 
     { 
      return null; 
     } 

    } 
    [DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] 
    private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons); 

} 

... 

form.Icon = IconExtractor.Extract("shell32.dll", 42, true); 

...은 MSDN 개발자 포럼에

1

그들 중 일부%Program Files%\Microsoft Visual Studio 10.0\Common7\VS2010ImageLibrary에서 사용할 수있는 - 다른 사람을 위해, 당신은

3

This thread는 솔루션을 제공 :

.NET에서 이들을 구현하는 일반적인 방법은 C : \ Program Files \ Microsoft Visual Studio X \ Common7 \ VS200XImageLibrary에있는 ZIP 파일의 그래픽을 사용하는 것입니다.

설치 한 Visual Studio 버전을 나타내지는 않지만 "200X"를 버전 번호로 바꾸어야합니다.

0

이 코드를 참조하십시오. 도움이 될 것입니다

public class ExtractIcon 
{ 
    [DllImport("Shell32.dll")] 
    private static extern int SHGetFileInfo(
     string pszPath, uint dwFileAttributes, 
     out SHFILEINFO psfi, uint cbfileInfo, 
     SHGFI uFlags); 

    private struct SHFILEINFO 
    { 
     public SHFILEINFO(bool b) 
     { 
      hIcon = IntPtr.Zero; iIcon = 0; dwAttributes = 0; szDisplayName = ""; szTypeName = ""; 
     } 
     public IntPtr hIcon; 
     public int iIcon; 
     public uint dwAttributes; 
     public string szDisplayName; 
     public string szTypeName; 
    }; 

    private enum SHGFI 
    { 
     SmallIcon = 0x00000001, 
     OpenIcon = 0x00000002, 
     LargeIcon = 0x00000000, 
     Icon = 0x00000100, 
     DisplayName = 0x00000200, 
     Typename = 0x00000400, 
     SysIconIndex = 0x00004000, 
     LinkOverlay = 0x00008000, 
     UseFileAttributes = 0x00000010 
    } 

    public static Icon GetIcon(string strPath, bool bSmall, bool bOpen) 
    { 
     SHFILEINFO info = new SHFILEINFO(true); 
     int cbFileInfo = Marshal.SizeOf(info); 
     SHGFI flags; 

     if (bSmall) 
      flags = SHGFI.Icon | SHGFI.SmallIcon; 
     else 
      flags = SHGFI.Icon | SHGFI.LargeIcon; 

     if (bOpen) flags = flags | SHGFI.OpenIcon; 

     SHGetFileInfo(strPath, 0, out info, (uint)cbFileInfo, flags); 

     return Icon.FromHandle(info.hIcon); 
    } 
}