使用Delphi我想在边框图标按钮上添加另一个按钮;关闭,最大化,最小化。关于如何做到这一点的任何想法?
答案 0 :(得分:5)
在Windows Aero之前,这很容易做到。您只需要在标题栏上方收听WM_NCPAINT
和WM_NCACTIVATE
消息,同样可以使用其他WM_NC*
消息来响应鼠标点击等,特别是WM_NCHITTEST
,WM_NCLBUTTONDOWN
和WM_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 :(得分:2)
Chris Rolliston撰写了一篇关于creating a custom title bar on Vista and Windows 7的详细博客。
他还撰写了follow up article并在CodeCentral上发布了示例代码。
答案 2 :(得分:1)
是的,将表单的边框样式属性设置为bsNone,并使用您喜欢的所有按钮和自定义行为实现自己的标题栏。