Einzelnen Beitrag anzeigen

w3seek
(Gast)

n/a Beiträge
 
#10

Re: DrawFocusRect "rund" darstellen

  Alt 24. Sep 2004, 11:34
ok, hab mich grad dran gemacht, hier ist er:

Delphi-Quellcode:
function DrawFocusRgn(hDC: HDC; hRgn: HRGN): Boolean;
var
  hPatternBmp: HBITMAP;
  hPatternBrush: HBRUSH;
  hOldBrush, hOldRgn: HGDIOBJ;
  rc: TRect;
const
  Pattern: array[0..3] of Cardinal = ($5555AAAA, $5555AAAA, $5555AAAA, $5555AAAA);
begin
  Result := false;
  hPatternBmp := CreateBitmap(8, 8, 1, 1, @Pattern[0]);
  if hPatternBmp <> 0 then
  begin
    GetRgnBox(hRgn, rc);
    hPatternBrush := CreatePatternBrush(hPatternBmp);
    if hPatternBrush <> 0 then
    begin
      hOldBrush := SelectObject(hDC, hPatternBrush);
      hOldRgn := SelectObject(hDC, hRgn);
      Result := PatBlt(hDC, rc.Left, rc.Top, rc.Right - rc.Left, rc.Bottom - rc.Top, PATINVERT);
      SelectObject(hDC, hOldRgn);
      SelectObject(hDC, hOldBrush);
      DeleteObject(hPatternBrush);
    end;
    DeleteObject(hPatternBmp);
  end;
end;

function DrawFocusRoundRect(hDC: HDC; nLeftRect, nTopRect, nRightRect, nBottomRect: Integer;
                            nWidthEllipse, nHeightEllipse: Integer;
                            nBorderWidth, nBorderHeight: Integer): Boolean;
var
  hRgnBorder, hRgnInner: HRGN;
  cmbResult: Integer;
begin
  Result := false;
  hRgnBorder := CreateRoundRectRgn(nLeftRect, nTopRect, nRightRect, nBottomRect,
                                   nWidthEllipse, nHeightEllipse);
  if hRgnBorder <> 0 then
  begin
    if ((nRightRect - nLeftRect > 2 * nBorderWidth) and
        (nBottomRect - nTopRect > 2 * nBorderHeight)) then
    begin
      hRgnInner := CreateRoundRectRgn(nLeftRect + nBorderWidth, nTopRect + nBorderHeight,
                                      nRightRect - nBorderWidth, nBottomRect - nBorderHeight,
                                      nWidthEllipse, nHeightEllipse);
      if hRgnInner <> 0 then
      begin
        cmbResult := CombineRgn(hRgnBorder, hRgnBorder, hRgnInner, RGN_DIFF);
        DeleteObject(hRgnInner);
        if cmbResult = ERROR then
        begin
          DeleteObject(hRgnBorder);
          Exit;
        end;
      end
      else
      begin
        DeleteObject(hRgnBorder);
        Exit;
      end;
    end;

    Result := DrawFocusRgn(hDC, hRgnBorder);
    DeleteObject(hRgnBorder);
  end;
end;
  Mit Zitat antworten Zitat