Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a border icon to the form

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

like image 551
Tim Avatar asked Aug 31 '10 19:08

Tim


1 Answers

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.

like image 147
Andreas Rejbrand Avatar answered Sep 23 '22 22:09

Andreas Rejbrand