Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#7

AW: ListView Header Farbe (Win32)

  Alt 17. Jan 2017, 19:17
Geänderte Version. So wie es aussehen sollte.
Ich kopiere jetzt den Hintergrund in ein temporäres DC um die Transparenz zu emulieren.
Das Problem ist aber genauso wie vorher ich kann das Window nicht aktualisieren
deshalb wird das DC immer wieder mit dem gleichen Inhalt übermalt.

Ich kann innerhalb des Threads WM_PAINT kein Invalidate aufrufen.
Krise hoch 3.

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;
  hDCBack: HDC;
  lp: TPoint;
begin
  Item.mask := HDI_TEXT or HDI_FORMAT or HDI_WIDTH;
  Item.pszText := buf;
  Item.fmt := HDF_LEFT and HDF_OWNERDRAW and 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);
// Neu
  hDCBack := CreateCompatibleDC(DC);
  GetClientRect(WinHandle, rc);

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

  SelectObject(hDCBack, SkinEngine.GetBackBitmap(GetParent(Handle)));
  BitBlt(DC, 0, 0, rc.Right, rc.Bottom, hDCBack, lp.x, lp.y, SRCCOPY);
// end Neu
  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) + lp.y;
    Rect.Left := Rect.Left + lp.x; // Neu
    DrawTextToDC(hDCBack, Text, Rect, Color, FFontName, FPointSize, FFontStyle, 0, 0);

// 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(hDCBack, Text, Rect, Color, FFontName, FPointSize, FFontStyle,
      FShadowOffset, 0);

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

// if GdipCreateFromHDC(DC, Graphics) = OK then
    if GdipCreateFromHDC(hDCBack, Graphics) = OK then
    begin
      Img := Cardinal(GetProperty(Handle, PROP_IMAGE_SELECTED));
      GetClientRect(WinHandle, rc);
// SkinEngine.PaintButton(Graphics, 4, Img, rc.Left, rc.Top, rc.Right, rc.bottom, BS_PUSHBUTTON);

      SkinEngine.PaintButton(Graphics, 4, Img, rc.Left + lp.x, lp.y, rc.Right, rc.bottom, BS_PUSHBUTTON);
// SkinEngine.PaintButton(Graphics, 4, Img, rcHeader.Left, rcHeader.Top, rcHeader.Right - rcHeader.Left,
// rcHeader.bottom, BS_PUSHBUTTON);
      SkinEngine.PaintButton(Graphics, 4, Img, rcHeader.Left + lp.x, lp.y, rcHeader.Right - rcHeader.Left,
        rcHeader.bottom, BS_PUSHBUTTON);

      GdipDeleteGraphics(Graphics);
    end;
    DeleteDC(hDCBack);
  end;
end;

gruss

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