2010-08-31 84 views
5

使用Delphi我想添加另一个按钮到边框图标按钮;关闭,最大化,最小化。任何想法如何做到这一点?添加边框图标到表格

回答

5

这在Windows Aero之前很容易做到。您只需收听WM_NCPAINTWM_NCACTIVATE消息以在字幕栏顶部绘制,并且类似地,您可以使用其他WM_NC*消息来响应鼠标点击等,特别是WM_NCHITTESTWM_NCLBUTTONDOWNWM_NCLBUTTONUP

例如,绘制标题栏上的绳子,你只有做

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. 

现在,这并不启用Aero的工作。不过,还有一种方法可以在标题栏上绘图;我已经这样做了,但它要复杂得多。查看this article作为一个工作示例。

1

是的,将表单的边框样式属性设置为bsNone,并使用您喜欢的所有按钮和自定义行为实现您自己的标题栏。