Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#5

AW: ListView Header Farbe (Win32)

  Alt 17. Jan 2017, 17:16
Zitat:
Bei mir kommt nur 0 zurück, wenn man das Handle der ListView in ListView_GetHeader übergibt.
Das funktioniert bei dir?
Ja das funktioniert so wie gezeigt weil das ListView gesubclassed ist.

Delphi-Quellcode:
function TSkinListView.CreateWindow(ParentHandle: hWnd): hWnd;
begin

  InitCommonControlsEx(iccex);

  if Visible then
  begin
    LStyle := WS_CHILD or LVS_REPORT or WS_CLIPCHILDREN or WS_CLIPSIBLINGS
      or LVS_SHOWSELALWAYS or LVS_SHAREIMAGELISTS or LVS_OWNERDRAWFIXED or WS_VISIBLE;
  end
  else
    LStyle := WS_CHILD or LVS_REPORT or WS_CLIPCHILDREN or WS_CLIPSIBLINGS
      or LVS_SHOWSELALWAYS or LVS_SHAREIMAGELISTS or LVS_OWNERDRAWFIXED;

  FHListView := CreateWindowEx(WS_EX_TRANSPARENT, WC_LISTVIEW, nil, LStyle,
    Left, Top, Width, Height, ParentHandle, DlgItemID, hInstance, nil);

  if FHListView <> 0 then
  begin
    SubClass(Handle);

    ImgBack := SkinEngine.skCreateImageFromFile(SelectedImg);
   
    if not assigned(PropList) then
      PropList := TStringList.Create;

    SetProperty(Handle, PROP_IMAGE_SELECTED, ImgBack);
    ShowWindow(Handle, Integer(Visible));

    ListView_SetExtendedListViewStyle(Handle, LVS_EX_FULLROWSELECT);

    HookedScrollbar(ParentHandle);
  end;

  Result := FHListView;
end;
Zitat:
Warum wendest du diese Vorgehensweise nicht auch auf den Column-Header daneben an?
Weil es keinen Column Header daneben gibt.
Dieser erstreckt sich über den gesamten Bereich der ListView hinter den eigentlichen Columns.

Zeichnen tue ich ihn so.
Headerproc..

Delphi-Quellcode:
function TSkinListView.ListViewHeaderProc(WinHandle: hWnd; Msg: UINT; wP: WParam; lP: LParam)
  : LRESULT;
var
  ps: TPaintstruct;
  rc, rcHeader: TRect;
  Dc: Hdc;
  ItemCount: Integer;
  IntI: Integer;
begin

  case Msg of
    WM_ERASEBKGND:
      begin
        Result := 1;
        exit;
      end;

    WM_LBUTTONDBLCLK:
      begin
        SkinEngine.FInvalidateRect(WinHandle, True);
      end;

    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);

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

          DrawHeaderItem(WinHandle, DC, IntI, rcHeader, True);
        end;

        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;
DrawHeaderItem
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;
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);

  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);
      // Hintergrund der Columns (Zeichne ich hier die Farbe anstelle des Button dann werden die Columns übermalt.)
      // bsp. FillRect.. bla. bla.
      SkinEngine.PaintButton(Graphics, 4, Img, rc.Left, rc.Top, rc.Right, rc.bottom, BS_PUSHBUTTON);
      // Columns
      SkinEngine.PaintButton(Graphics, 4, Img, rcHeader.Left, rcHeader.Top, rcHeader.Right - rcHeader.Left,
        rcHeader.bottom, BS_PUSHBUTTON);

      GdipDeleteGraphics(Graphics);
    end;
  end;
end;
Zitat:
hast du eine Delphiversion höher als XE2?
Nein D2010.

gruss

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