ExtractAssociatedIcon returns null

前端 未结 1 1292
醉梦人生
醉梦人生 2021-01-14 09:16

I\'m using the ExtractAssociatedIcon method to retrieve the icon for the file. My hope is to retrieve the same icon that a user would see in their explorer wind

相关标签:
1条回答
  • 2021-01-14 09:53

    (Comment turned into post - CTIP)

    Check out the link here which eventually leads to P/Invoke.net with the following code:

    [DllImport("shell32.dll")]
    static extern IntPtr ExtractAssociatedIcon(IntPtr hInst, StringBuilder lpIconPath, out ushort lpiIcon);
    
    [DllImport("shell32.dll")]
    static extern IntPtr ExtractIcon(IntPtr hInst, string lpszExeFileName, int nIconIndex);
    

    _

    ushort uicon;
    StringBuilder strB = new StringBuilder(YOUR_FILE_PATH);
    IntPtr handle = ExtractAssociatedIcon(this.Handle, strB, out uicon);
    Icon ico = Icon.FromHandle(handle);
    
    return ico.ToBitmap();
    
    0 讨论(0)
提交回复
热议问题