Einzelnen Beitrag anzeigen

Benutzerbild von turboPASCAL
turboPASCAL

Registriert seit: 8. Mai 2005
Ort: Sondershausen
4.274 Beiträge
 
Delphi 6 Personal
 
#4

Re: Button in Caption von ToolWin

  Alt 19. Mai 2005, 13:22
Sodele,
Button in der Caption (mit kleiner Macke bei Mouseover).

Delphi-Quellcode:
...
procedure TForm1.DrawTitleBtnRect(BtnPos: Byte; btnState: TBtnState);
var
  cXFrame, cYFrame, ccBorder: Integer; // Rahmendicke
  cxSize, cySize: Integer; // Hoehe & Breite der Buttons in der Titelleiste
  Bitmap: TBitmap; // Btn Bitmap
  x: TBitmap; // *** Bitmap
begin
  if Self.BorderStyle in [bsNone] then Exit; // No Frame no Button

  if Self.BorderStyle in [bsSizeToolWin, bsToolWindow] then
  begin
    // small Button Grösse ermitteln
    cxSize := GetSystemMetrics(SM_CXSMSIZE) - 2; // -2 Btn-Rand
    cySize := GetSystemMetrics(SM_CYSMSIZE) - 2; // -2 Btn-Rand
  end else
  begin
    // Button Grösse ermitteln
    cxSize := GetSystemMetrics(SM_CXSIZE) - 2; // -2 Btn-Rand
    cySize := GetSystemMetrics(SM_CYSIZE) - 2; // -2 Btn-Rand
  end;

  // Rändergrössen der Frame ermitteln
  if Self.BorderStyle in [bsToolWindow]
    then ccBorder := 0 else ccBorder := GetSystemMetrics(SM_CXBORDER);

  if Self.BorderStyle in [bsDialog, bsSingle] then
  begin // normal Frame
    cXFrame := GetSystemMetrics(SM_CXDLGFRAME) + ccBorder;
    cYFrame := GetSystemMetrics(SM_CYDLGFRAME) + ccBorder;
  end else
  begin // sizeable Frame
    cXFrame := GetSystemMetrics(SM_CXSIZEFRAME) + ccBorder;
    cYFrame := GetSystemMetrics(SM_CYSIZEFRAME) + ccBorder;
  end;

  // Button Rect
  BtnCaptionRect := Bounds((Self.Width - cXFrame) - (BtnPos * cxSize), cYFrame,
    cxSize, cySize);

  Canvas.Handle := GetWindowDC(Self.Handle); //Get Device for drawing

  try
    Bitmap := TBitmap.Create;

    // *** Bitmap File laden
    x := TBitmap.Create;
    x.LoadFromFile('btn_up_over_down_XP.bmp');

    Bitmap.Width := cxSize;
    Bitmap.Height:= cxSize;

    // Abfragen des Btn Status / Btn vom x-Bitmap ins Bitmap kopieren
    if btnUp in btnState then
    begin
      Bitmap.Canvas.CopyRect(Rect(0,0,cxSize,cxSize), x.Canvas, Rect(0,0,23,23));
    end else
    if btnDown in btnState then
    begin
      Bitmap.Canvas.CopyRect(Rect(0,0,cxSize,cxSize), x.Canvas, Rect(23+23,0,23+23+23,23));
    end else
    if btnOver in btnState then
    begin
      Bitmap.Canvas.CopyRect(Rect(0,0,cxSize,cxSize), x.Canvas, Rect(23,0,23+23,23));
    end else
    if btnInActive in btnState then
    begin
    end;

    // Btn Transparent ?
    if btnTransparent in btnState then
    begin
      Bitmap.Transparent := True;
      Bitmap.TransParentColor := clFuchsia;
    end;

    // Btn Stretchen ?
    if btnStretch in btnState then
      Canvas.StretchDraw(BtnCaptionRect, Bitmap)
    else
      Canvas.Draw(BtnCaptionRect.Left, BtnCaptionRect.Top, Bitmap);

  finally
    ...
    ...
  end;
end;
...
Source Code im Anhang
Angehängte Dateien
Dateityp: zip btnincaption_203.zip (13,9 KB, 35x aufgerufen)
Matti
  Mit Zitat antworten Zitat