Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#8

AW: ListView Header Farbe (Win32)

  Alt 19. Jan 2017, 10:01
Funktioniert jetzt wollte nur das Ergebnis mitteilen.
Subclass Header
Delphi-Quellcode:
    WM_PAINT:
      begin
        GetClientRect(WinHandle, rc);

        Dc := BeginPaint(WinHandle, ps);

        if not SkinEngine.Composited(WinHandle) then
          Dc := SkinEngine.DoubleBuffer(ps.Hdc, rc.Right, rc.Bottom, CreateBuffer);

        hDCBack := CreateCompatibleDC(Dc);

        GetWindowRect(WinHandle, rw);
        p.x := rw.Left;
        p.y := rw.Top;
        ScreenToClient(GetParent(Handle), p);

        SelectObject(hDCBack, SkinEngine.GetBackBitmap(GetParent(Handle)));
        BitBlt(Dc, 0, 0, rcHeader.Right, rcHeader.Bottom, hDCBack, p.x, p.y, SRCCOPY);

        ItemCount := Header_GetItemCount(WinHandle);
        for IntI := 0 to ItemCount - 1 do
        begin
          Header_GetItemRect(WinHandle, IntI, @rcHeader);

          DrawHeaderItem(WinHandle, Dc, IntI, rcHeader, True);
        end;
        DeleteDC(hDCBack);

        if not SkinEngine.Composited(WinHandle) then
          SkinEngine.DoubleBuffer(0, 0, 0, DestroyBuffer)
        else
          ReleaseDC(WinHandle, Dc);

        EndPaint(WinHandle, ps);
        Result := 0;
        exit;
      end;

  end;
  Result := CallWindowProc(FPrevHeaderProc, WinHandle, Msg, wP, lP);
end;
Drawitems
Delphi-Quellcode:
procedure TSkinListView.DrawHeaderItem(WinHandle: hWnd; Dc: Hdc; Index: Integer; Rect: TRect;
  Selected: Bool);
var
  Text: PWideChar;
  buf: array [0 .. 255] of Char;
  Item: THDItem;
  rcHeader: TRect;
  Img: Cardinal;
  Graphics: Cardinal;
  rc: TRect;
  rw: TRect;
  lP: TPoint;
begin
  Item.mask := HDI_TEXT or HDI_FORMAT { or HDI_BITMAP } or HDI_WIDTH;
  Item.pszText := buf;
  Item.fmt := HDF_LEFT or HDF_OWNERDRAW { or HDF_BITMAP } or HDF_STRING;
  Item.cchTextMax := sizeof(buf);

  Header_GetItemRect(WinHandle, Index, @rcHeader);

  ZeroMemory(@buf, sizeof(buf));
  Header_GetItem(WinHandle, Index, Item);
  Text := buf;

  SetBkMode(Dc, TRANSPARENT);

  if GetShadow then
  begin
    if IsWindowEnabled(WinHandle) then
      Color := GetShadowColor
    else
      Color := RGB(255, 255, 255);

    Rect.Top := (((rcHeader.Bottom - FPointSize) div 2) div 2 + 1);
    DrawTextToDC(Dc, Text, Rect, Color, FFontName, FPointSize, FFontStyle, 0, 0);

    if IsWindowEnabled(WinHandle) then
    begin
      if Selected then
        Color := AktForecolor
      else
        Color := InAktForecolor;
    end
    else
      Color := RGB(140, 140, 140);

    DrawTextToDC(Dc, Text, Rect, Color, FFontName, FPointSize, FFontStyle, FShadowOffset, 0);

    if GdipCreateFromHDC(Dc, Graphics) = OK then
    begin
      Img := Cardinal(GetProperty(Handle, PROP_IMAGE_SELECTED));
      GetClientRect(WinHandle, rc);

      GetWindowRect(WinHandle, rw);
      lP.x := rw.Left;
      lP.y := rw.Top;
      ScreenToClient(GetParent(Handle), lP);

      SkinEngine.PaintButton(Graphics, 4, Img, rc.Left, rc.Top, rc.Right, rc.Bottom, BS_PUSHBUTTON);

      SkinEngine.PaintButton(Graphics, 4, Img, rcHeader.Left, rcHeader.Top,
        rcHeader.Right - rcHeader.Left, rcHeader.Bottom, BS_PUSHBUTTON);

      GdipDeleteGraphics(Graphics);
    end;
  end;
end;
Ergebnis siehe Pic.
Kann mich jetzt mit den Header Icons beschäftigen.

gruss

Geändert von EWeiss (11. Jul 2019 um 15:45 Uhr)
  Mit Zitat antworten Zitat