Add a border icon to the form
Asked Answered
K

3

5

Using Delphi I would like to add another button to the border icon buttons; close, maximize, minimize. Any ideas on how to do this?

Kimble answered 31/8, 2010 at 19:7 Comment(0)
A
5

This was easy to do prior to Windows Aero. You simply had to listen to the WM_NCPAINT and WM_NCACTIVATE messages to draw on top of the caption bar, and similarly you could use the other WM_NC* messages to respond to mouse clicks etc, in particular WM_NCHITTEST, WM_NCLBUTTONDOWN, and WM_NCLBUTTONUP.

For instance, to draw a string on the title bar, you only had to do

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
  protected
    procedure WMNCPaint(var Msg: TWMNCPaint); message WM_NCPAINT;
    procedure WMNCActivate(var Msg: TWMNCActivate); message WM_NCACTIVATE;
  private
    procedure DrawOnCaption;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.WMNCActivate(var Msg: TWMNCActivate);
begin
  inherited;
  DrawOnCaption;
end;

procedure TForm1.WMNCPaint(var Msg: TWMNCPaint);
begin
  inherited;
  DrawOnCaption;
end;

procedure TForm1.DrawOnCaption;
var
  dc: HDC;
begin
  dc := GetWindowDC(Handle);
  try
    TextOut(dc, 20, 2, 'test', 4);
  finally
    ReleaseDC(Handle, dc);
  end;
end;

end.

Now, this doesn't work with Aero enabled. Still, there is a way to draw on the caption bar; I have done that, but it is far more complicated. See this article for a working example.

Autotrophic answered 31/8, 2010 at 19:40 Comment(0)
A
2

Chris Rolliston wrote a detailed blog about creating a custom title bar on Vista and Windows 7.

He also wrote a follow up article and posted example code on CodeCentral.

Apopemptic answered 1/9, 2010 at 8:30 Comment(0)
F
1

Yes, set the form's border style property to bsNone and implement your own title bar with all the buttons and custom behaviour you like.

Falzetta answered 1/9, 2010 at 3:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.