BExplorer.Shell.ShellView.ProcessCustomDraw C# (CSharp) Method

ProcessCustomDraw() private method

private ProcessCustomDraw ( Message &m, NMHDR &nmhdr ) : void
m Message
nmhdr NMHDR
return void
    private void ProcessCustomDraw(ref Message m, ref NMHDR nmhdr) {
      if (nmhdr.hwndFrom == this.LVHandle) {
        #region Starting

        User32.SendMessage(this.LVHandle, 296, User32.MAKELONG(1, 1), 0);
        var nmlvcd = (User32.NMLVCUSTOMDRAW)m.GetLParam(typeof(User32.NMLVCUSTOMDRAW));
        var index = (Int32)nmlvcd.nmcd.dwItemSpec;
        var hdc = nmlvcd.nmcd.hdc;

        var sho = Items.Count > index ? Items[index] : null;

        Color? textColor = null;
        if (sho != null && this.LVItemsColorCodes != null && this.LVItemsColorCodes.Count > 0 && !String.IsNullOrEmpty(sho.Extension)) {
          var extItemsAvailable = this.LVItemsColorCodes.Where(c => c.ExtensionList.Contains(sho.Extension)).Count() > 0;
          if (extItemsAvailable) {
            var color = this.LVItemsColorCodes.SingleOrDefault(c => c.ExtensionList.ToLowerInvariant().Contains(sho.Extension)).TextColor;
            textColor = Color.FromArgb(color.A, color.R, color.G, color.B);
          }
        }

        #endregion Starting

        switch (nmlvcd.nmcd.dwDrawStage) {
          case CustomDraw.CDDS_PREPAINT:

            #region Case

            m.Result = (IntPtr)(CustomDraw.CDRF_NOTIFYITEMDRAW | CustomDraw.CDRF_NOTIFYPOSTPAINT | 0x40);
            break;

          #endregion Case

          case CustomDraw.CDDS_POSTPAINT:

            #region Case

            m.Result = (IntPtr)CustomDraw.CDRF_SKIPDEFAULT;
            break;

          #endregion Case

          case CustomDraw.CDDS_ITEMPREPAINT:

            #region Case

            if (nmlvcd.clrTextBk != 0) {
              if ((nmlvcd.nmcd.uItemState & CDIS.DROPHILITED) == CDIS.DROPHILITED && index != _LastDropHighLightedItemIndex) {
                nmlvcd.nmcd.uItemState = CDIS.DEFAULT;
                Marshal.StructureToPtr(nmlvcd, m.LParam, false);
              }

              if (index == _LastDropHighLightedItemIndex) {
                nmlvcd.nmcd.uItemState |= CDIS.DROPHILITED;
                Marshal.StructureToPtr(nmlvcd, m.LParam, false);
              }

              if (textColor == null) {
                m.Result = (IntPtr)(CustomDraw.CDRF_NOTIFYPOSTPAINT | CustomDraw.CDRF_NOTIFYSUBITEMDRAW | 0x40);
              } else {
                nmlvcd.clrText = (UInt32)ColorTranslator.ToWin32(textColor.Value);
                Marshal.StructureToPtr(nmlvcd, m.LParam, false);

                m.Result =
                        (IntPtr)(CustomDraw.CDRF_NEWFONT | CustomDraw.CDRF_NOTIFYPOSTPAINT | CustomDraw.CDRF_NOTIFYSUBITEMDRAW);
              }
            } else {
              m.Result =
                      (IntPtr)(CustomDraw.CDRF_SKIPDEFAULT);
            }


            break;

          #endregion Case

          case CustomDraw.CDDS_ITEMPREPAINT | CustomDraw.CDDS_SUBITEM:

            #region Case

            if (textColor == null) {
              m.Result = (IntPtr)CustomDraw.CDRF_DODEFAULT;
            } else {
              nmlvcd.clrText = (UInt32)ColorTranslator.ToWin32(textColor.Value);
              Marshal.StructureToPtr(nmlvcd, m.LParam, false);
              m.Result = (IntPtr)CustomDraw.CDRF_NEWFONT;
            }
            break;

          #endregion Case

          case CustomDraw.CDDS_ITEMPOSTPAINT:
            this.ProcessCustomDrawPostPaint(ref m, nmlvcd, index, hdc, sho, textColor);
            break;
        }
      }
    }
ShellView