Einzelnen Beitrag anzeigen

perle

Registriert seit: 8. Apr 2004
183 Beiträge
 
Delphi 7 Enterprise
 
#3

Re: Rahmen um Controls zeichnen

  Alt 6. Dez 2004, 16:58
ich zeichne folgendermaßen:


Delphi-Quellcode:
procedure TWindowHandle.DrawRect(toChildWnd: Boolean = False); // Ref# 007

  procedure FrameWindow(Wnd: HWnd);
  var
    Rect: TRect;
    DC: hDC;
    OldPen, Pen: hPen;
    OldBrush, Brush: hBrush;
    X2, Y2: Integer;
  begin
    { Get the target window's rect and DC }
    GetWindowRect(Wnd, Rect);
    DC := GetWindowDC(Wnd);
    { Set ROP appropriately for highlighting }
    SetROP2(DC, R2_NOT);
    { Select brush and pen }
    Pen := CreatePen(PS_InsideFrame, 4, RGB(255,0,0));
    OldPen := SelectObject(DC, Pen);
    Brush := GetStockObject(Null_Brush);
    OldBrush := SelectObject(DC, Brush);
    { Set dimensions of highlight }
    X2 := Rect.Right - Rect.Left;
    Y2 := Rect.Bottom - Rect.Top;
    { Draw highlight box }
    Rectangle(DC, 0, 0, X2, Y2);
    { Clean up }
    SelectObject(DC, OldBrush);
    SelectObject(DC, OldPen);
    ReleaseDC(Wnd, DC);
    { Do NOT delete the brush, because it was a stock object }
    DeleteObject(Pen);
  end;

var
  hNewWnd : HWND;
begin
  hNewWnd := 0;
  case toChildWnd of
    TRUE : hNewWnd := FHandle;
    FALSE: hNewWnd := FMainHandle;
  end;
  { To avoid flickering, remove the old frame ONLY if moved to new window }
  if hNewWnd <> hOldWnd then
  begin
    if hOldWnd <> 0 then
      FrameWindow(hOldWnd);
    if hNewWnd <> 0 then
      FrameWindow(hNewWnd);
    hOldWnd := hNewWnd;
  end;

end;
diese prozedur rufe ich in einem Timer immer wieder mit einem Neuen handle auf
  Mit Zitat antworten Zitat