private unsafe void DrawTreeItem( string itemText, int imageIndex, Gdi32.HDC dc, RECT rcIn, int state, int backColor, int textColor) { Size size = new Size(); var rc2 = new RECT(); var rc = new RECT(rcIn.left, rcIn.top, rcIn.right, rcIn.bottom); ImageList imagelist = ImageList; IntPtr hfontOld = IntPtr.Zero; // Select the font of the dialog, so we don't get the underlined font // when the item is being tracked using var fontSelection = new Gdi32.SelectObjectScope( dc, (state& STATE_HOT) != 0 ? (Gdi32.HGDIOBJ)Parent.FontHandle : default); GC.KeepAlive(Parent); // Fill the background if (((state & STATE_SELECTED) != 0) && !_hbrushDither.IsNull) { FillRectDither(dc, rcIn); Gdi32.SetBkMode(dc, Gdi32.BKMODE.TRANSPARENT); } else { Gdi32.SetBkColor(dc, backColor); Gdi32.ExtTextOutW(dc, 0, 0, Gdi32.ETO.CLIPPED | Gdi32.ETO.OPAQUE, ref rc, null, 0, null); } // Get the height of the font Gdi32.GetTextExtentPoint32W(dc, itemText, itemText.Length, ref size); // Draw the caption rc2.left = rc.left + SIZE_ICON_X + 2 * PADDING_HORZ; rc2.top = rc.top + (((rc.bottom - rc.top) - size.Height) >> 1); rc2.bottom = rc2.top + size.Height; rc2.right = rc.right; Gdi32.SetTextColor(dc, textColor); User32.DrawTextW( dc, itemText, itemText.Length, ref rc2, User32.DT.LEFT | User32.DT.VCENTER | User32.DT.END_ELLIPSIS | User32.DT.NOPREFIX); ComCtl32.ImageList.Draw( imagelist, imageIndex, dc, PADDING_HORZ, rc.top + (((rc.bottom - rc.top) - SIZE_ICON_Y) >> 1), ComCtl32.ILD.TRANSPARENT); // Draw the hot-tracking border if needed if ((state & STATE_HOT) != 0) { int savedColor; // top left savedColor = Gdi32.SetBkColor(dc, ColorTranslator.ToWin32(SystemColors.ControlLightLight)); rc2.left = rc.left; rc2.top = rc.top; rc2.bottom = rc.top + 1; rc2.right = rc.right; Gdi32.ExtTextOutW(dc, 0, 0, Gdi32.ETO.OPAQUE, ref rc2, null, 0, null); rc2.bottom = rc.bottom; rc2.right = rc.left + 1; Gdi32.ExtTextOutW(dc, 0, 0, Gdi32.ETO.OPAQUE, ref rc2, null, 0, null); // bottom right Gdi32.SetBkColor(dc, ColorTranslator.ToWin32(SystemColors.ControlDark)); rc2.left = rc.left; rc2.right = rc.right; rc2.top = rc.bottom - 1; rc2.bottom = rc.bottom; Gdi32.ExtTextOutW(dc, 0, 0, Gdi32.ETO.OPAQUE, ref rc2, null, 0, null); rc2.left = rc.right - 1; rc2.top = rc.top; Gdi32.ExtTextOutW(dc, 0, 0, Gdi32.ETO.OPAQUE, ref rc2, null, 0, null); Gdi32.SetBkColor(dc, savedColor); } }