【发布时间】:2011-04-06 10:53:29
【问题描述】:
使用 Delphi 我想在边框图标按钮上添加另一个按钮;关闭,最大化,最小化。关于如何做到这一点的任何想法?
【问题讨论】:
标签: windows delphi delphi-2007 titlebar custom-titlebar
使用 Delphi 我想在边框图标按钮上添加另一个按钮;关闭,最大化,最小化。关于如何做到这一点的任何想法?
【问题讨论】:
标签: windows delphi delphi-2007 titlebar custom-titlebar
Chris Rolliston 写了一篇关于creating a custom title bar on Vista and Windows 7 的详细博客。
他还写了一个follow up article,并在CodeCentral上发布了示例代码。
【讨论】:
是的,将表单的边框样式属性设置为 bsNone 并使用您喜欢的所有按钮和自定义行为实现您自己的标题栏。
【讨论】:
在 Windows Aero 之前,这很容易做到。您只需收听WM_NCPAINT 和WM_NCACTIVATE 消息即可在标题栏顶部绘制,同样您可以使用其他WM_NC* 消息来响应鼠标点击等,特别是WM_NCHITTEST、@987654326 @ 和 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。
【讨论】: