public static extern BOOL ImageList_Draw( IntPtr himl, int i, HDC hdcDst, int x, int y, ILD fStyle );
public static BOOL DrawEx(IHandle himl, int i, HandleRef hdcDst, int x, int y, int dx, int dy, int rgbBk, int rgbFg, ILD fStyle) { BOOL result = DrawEx(himl.Handle, i, hdcDst.Handle, x, y, dx, dy, rgbBk, rgbFg, fStyle); GC.KeepAlive(himl); GC.KeepAlive(hdcDst.Wrapper); return(result); }
public static extern BOOL DrawEx(IntPtr himl, int i, IntPtr hdcDst, int x, int y, int dx, int dy, int rgbBk, int rgbFg, ILD fStyle);
public static extern IntPtr ImageList_GetIcon(IntPtr himl, int index, ILD flags);
public static BOOL Draw(IHandle himl, int i, Gdi32.HDC hdcDst, int x, int y, ILD fStyle) { BOOL result = Draw(himl.Handle, i, hdcDst, x, y, fStyle); GC.KeepAlive(himl); return(result); }
public static extern BOOL Draw(IntPtr himl, int i, Gdi32.HDC hdcDst, int x, int y, ILD fStyle);
private static extern IntPtr ImageList_GetIcon(IntPtr himl, int i, ILD flags);
/// <summary> /// Queries the internal Hashtable of IConIndexes and returns the IconIndex for the requested ShellItem. /// </summary> /// <param name="item">The ShellItem for which the IconIndex is requested</param> /// <param name="GetOpenIcon">true if the "open" IconIndex is requested</param> /// <param name="GetSelectedIcon">true if the "Selected" Icon is requested</param> /// <returns>The true IConIndex into the per process ImageList for the ShellItem given as a parameter</returns> public static int GetIconIndex(ShellItem item, bool GetOpenIcon = false, bool GetSelectedIcon = false) { Initializer(); bool HasOverlay = false; //true if it's an overlay int rVal; //The returned Index SHGFI dwflag = SHGFI.SYSICONINDEX | SHGFI.PIDL | SHGFI.ICON; int dwAttr = 0; //build Key into HashTable for this Item int Key = (int)(!GetOpenIcon ? item.IconIndexNormalOrig * 256 : item.IconIndexOpenOrig * 256); //With item if (item.IsLink) { Key = Key | 1; dwflag = dwflag | SHGFI.LINKOVERLAY; HasOverlay = true; } if (item.IsShared) { Key = Key | 2; dwflag = dwflag | SHGFI.ADDOVERLAYS; HasOverlay = true; } if (GetSelectedIcon) { Key = Key | 4; dwflag = dwflag | SHGFI.SELECTED; HasOverlay = true; //not really an overlay, but handled the same } if (m_Table.ContainsKey(Key)) { rVal = (int)m_Table[Key]; mCnt += 1; } else if (!HasOverlay) //for non-overlay icons, we already have { rVal = Key / 256; // the right index -- put in table m_Table[Key] = rVal; bCnt += 1; } else //don't have iconindex for an overlay, get it. { //This is the tricky part -- add overlaid Icon to systemimagelist // use of SmallImageList from Calum McLellan SHFILEINFO shfi = new SHFILEINFO(); SHFILEINFO shfi_small = new SHFILEINFO(); IntPtr HR; IntPtr HR_SMALL; if (item.IsFileSystem && !item.IsDisk && !item.IsFolder) { dwflag = dwflag | SHGFI.USEFILEATTRIBUTES; dwAttr = (int)SHGFI.FILE_ATTRIBUTE_NORMAL; } //UPDATE: OpenIcon with overlay if (GetOpenIcon) { dwflag = dwflag | SHGFI.OPENICON; } HR = Shell32.SHGetFileInfo(item.Pidl, dwAttr, out shfi, cbFileInfo, dwflag); HR_SMALL = Shell32.SHGetFileInfo(item.Pidl, dwAttr, out shfi_small, cbFileInfo, dwflag | SHGFI.SMALLICON); //m_Mutex.WaitOne() int rVal2; lock (SILMLock) { rVal = ImageList_ReplaceIcon(m_smImgList, -1, shfi_small.hIcon); //Debug.Assert(rVal > -1, "Failed to add overlaid small icon"); rVal2 = ImageList_ReplaceIcon(m_lgImgList, -1, shfi.hIcon); // Jens' version if (m_xlgImgList != IntPtr.Zero) //Not set on Windows earlier than XP { ILD flags = ILD.NORMAL; //= 0 //5/9/2013 - JDP if (item.IsLink) { flags = flags | (ILD)INDEXTOOVERLAYMASK(ovlLink); } if (item.IsShared) { flags = flags | (ILD)INDEXTOOVERLAYMASK(ovlShare); } IntPtr hIcon = IntPtr.Zero; rVal = GetNonOverlayIndex(ref item, GetOpenIcon); hIcon = ImageList_GetIcon(m_xlgImgList, rVal, flags); rVal = ImageList_ReplaceIcon(m_xlgImgList, -1, hIcon); int rCnt = ImageList_GetImageCount(m_jumboImgList); //Debug.Assert(rVal > -1, "Failed to add overlaid xl icon"); User32.DestroyIcon(hIcon); //Debug.Assert(rVal == rVal2, "XL & Large Icon Indices are Different"); } // This fails at rVal = ImageList_ReplaceIcon (incomplete implementation of interface??) if (m_jumboImgList != IntPtr.Zero) //Not set on Windows earlier than XP { IntPtr hIcon = IntPtr.Zero; rVal = GetNonOverlayIndex(ref item, GetOpenIcon); ILD flags = ILD.NORMAL; if (item.IsLink) { flags = flags | (ILD)INDEXTOOVERLAYMASK(ovlLink); } if (item.IsShared) { flags = flags | (ILD)INDEXTOOVERLAYMASK(ovlShare); } hIcon = ImageList_GetIcon(m_jumboImgList, rVal, flags); rVal = ImageList_ReplaceIcon(m_jumboImgList, -1, hIcon); if (rVal < 0) //5/11/2013 - JDP { rVal = rVal2; //5/11/2013 - JDP } //5/11/2013 - JDP //Debug.Assert(rVal > -1, "Failed to add overlaid Jumbo icon"); User32.DestroyIcon(hIcon); //Debug.Assert(rVal == rVal2, "Jumbo & Large Icon Indices are Different"); } } //m_Mutex.ReleaseMutex() User32.DestroyIcon(shfi.hIcon); User32.DestroyIcon(shfi_small.hIcon); if (rVal < 0 || rVal != rVal2) { // FAB //throw new ApplicationException("Failed to add Icon for " + item.DisplayName); //MessageBox.Show("Failed to add Icon for " + item.DisplayName); Console.Write("\nFailed to add Icon for " + item.DisplayName); } m_Table[Key] = rVal; } //End With return(rVal); }
public static extern BOOL Draw(IntPtr himl, int i, HandleRef hdcDst, int x, int y, ILD fStyle);
public static partial BOOL Draw(IntPtr himl, int i, Gdi32.HDC hdcDst, int x, int y, ILD fStyle);
public static extern HICON ImageList_GetIcon( IntPtr himl, int i, ILD flags );