Einzelnen Beitrag anzeigen

alzaimar
(Moderator)

Registriert seit: 6. Mai 2005
Ort: Berlin
4.956 Beiträge
 
Delphi 2007 Enterprise
 
#3

Re: TCheckComboBox: Komponente überarbeiten???

  Alt 17. Jan 2009, 11:55
Delphi-Quellcode:
procedure TATCheckedComboBox.CNDrawItem(var Message: TWMDrawItem);
var
  State: TOwnerDrawState;
  rcBitmap, rcText: Trect;
  nCheck: integer; // 0 - No check, 1 - Empty check, 2 - Checked
  nState: integer;
  strText: string;
  ItId: Integer;
  dc: HDC;
begin
  with Message.DrawItemStruct^ do
  begin
    State := TOwnerDrawState(LongRec(itemState).Lo);
    dc := hDC;
    rcBitmap := rcItem;
    rcText := rcItem;
    ItId := itemID;
  end;
   // Check if we are drawing the static portion of the combobox
  if (itID < 0) then
  begin
    RecalcText();
    strText := m_strText;
    nCheck := 0;
  end
  else
  begin
    strtext := Items[ItId];
    rcBitmap.Left := 2;
    rcBitmap.Top := rcText.Top + (rcText.Bottom - rcText.Top - FCheckWidth) div 2;
    rcBitmap.Right := rcBitmap.Left + FCheckWidth;
    rcBitmap.Bottom := rcBitmap.Top + FCheckHeight;

    rcText.left := rcBitmap.right;
    nCheck := 1;
    if IsChecked(ItId) then
      inc(nCheck);
  end;
  if (nCheck > 0) then
  begin
    SetBkColor(dc, GetSysColor(COLOR_WINDOW));
    SetTextColor(dc, GetSysColor(COLOR_WINDOWTEXT));
    nState := DFCS_BUTTONCHECK;
    if (nCheck > 1) then
      nState := nState or DFCS_CHECKED;
    DrawFrameControl(dc, rcBitmap, DFC_BUTTON, nState);
  end;

  if (odSelected in State) then
  begin
    SetBkColor(dc, $0091622F);
    SetTextColor(dc, GetSysColor(COLOR_HIGHLIGHTTEXT));
  end
  else
  begin
    if (nCheck = 0) then
    begin
      SetTextColor(dc, ColorToRGB(Font.Color));
      SetBkColor(dc, ColorToRGB(FColorNotFocus));
    end
    else
    begin
      SetTextColor(dc, ColorToRGB(Font.Color));
      if ncheck = 1 then
        SetBkColor(dc, ColorToRGB(Brush.Color))
      else
        SetBkColor(dc, clRed); // <<----- hier

    end;
  end;
  if itID >= 0 then
    strText := ' ' + strtext;
  ExtTextOut(dc, 0, 0, ETO_OPAQUE, @rcText, nil, 0, nil);
  DrawText(dc, pchar(strText), Length(strText), rcText, DT_SINGLELINE or DT_VCENTER or DT_END_ELLIPSIS);
  if odFocused in State then DrawFocusRect(dc, rcText);
end;
Zeichnet die angecheckten (aua!) Einträge rot.
"Wenn ist das Nunstruck git und Slotermeyer? Ja! Beiherhund das Oder die Flipperwaldt gersput!"
(Monty Python "Joke Warefare")
  Mit Zitat antworten Zitat