简体   繁体   English

在旧版 Delphi 中更改 TListView header 的背景颜色

[英]Change background color of TListView header in older Delphi

An old app using Delphi 7, but should be similar code in older Delphi versions up to perhaps 2010. I need to change the background color of a TListView header so I can offer a dark theme.一个使用 Delphi 7 的旧应用程序,但在 2010 年之前的旧 Delphi 版本中应该是类似的代码。我需要更改 TListView Z099FB995346F31C749F6E40DB0F395E3 的背景颜色,以便可以提供深色主题。 I can change the colors of everything else.我可以更改其他所有内容的 colors。 I found the thread below which apparently works for changing the font color on a column header, but I need to adjust the background color of the entire header as well.我发现下面的线程显然适用于更改 header 列上的字体颜色,但我还需要调整整个 header 的背景颜色。

Delphi: ListView (vsReport) single column header caption with custom font color? Delphi:ListView(vsReport)单列header标题与自定义字体颜色?

Can someone please help as I am lost.有人可以帮忙,因为我迷路了。 Windows message notifications are beyond my comprehension. Windows 消息通知超出了我的理解。

Many thanks.非常感谢。

I'm fairly proud of myself and somehow found bits and pieces of code that all went together to make it all work.我为自己感到相当自豪,并以某种方式找到了所有代码的点点滴滴,这些代码都可以一起工作。 Something like this...像这样的东西...

procedure TTntListView.WMNotify(var AMessage: TWMNotify);
const
  DT_ALIGN: array[TAlignment] of integer = (DT_LEFT, DT_RIGHT, DT_CENTER);
var
  NMCustomDraw: TNMCustomDraw;
  i: Integer;
  r: TRect;
begin
  if (AMessage.NMHdr.hwndFrom = FHeaderHandle) and
    (AMessage.NMHdr.code = NM_CUSTOMDRAW) then
  begin
    NMCustomDraw := PNMCustomDraw(TMessage(AMessage).LParam)^;
    case NMCustomDraw.dwDrawStage of
      CDDS_PREPAINT: AMessage.Result := CDRF_NOTIFYITEMDRAW;
      CDDS_ITEMPREPAINT: begin
        i := NMCustomDraw.dwItemSpec;
        r := NMCustomDraw.rc;
        FillRect(NMCustomDraw.hdc, r, Sender.Canvas.Brush.Handle);
        SetBkColor(NMCustomDraw.hdc,  ColorToRGB(Sender.Canvas.Brush.Color));
        SetTextColor(NMCustomDraw.hdc, ColorToRGB(Sender.Canvas.Font.Color));
        DrawEdge(NMCustomDraw.hdc,r,EDGE_SUNKEN,BF_LEFT);
        Inc(r.Left,2);
        Dec(r.Right,2);
        if Sender.Column[i].Alignment = taLeftJustify then Inc(r.Left,3)
        else Dec(r.Right,3);
        DrawTextW(NMCustomDraw.hdc,
          pWideChar(Sender.Column[i].Caption),
          length(Sender.Column[i].Caption),
          r,
          DT_SINGLELINE or DT_ALIGN[Sender.Column[i].Alignment] or
            DT_VCENTER or DT_END_ELLIPSIS);
        Message.Result := CDRF_SKIPDEFAULT;
      end;
      else AMessage.Result := CDRF_DODEFAULT;
    end;
  end
  else inherited;
end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM