向表单添加边框图标

发布于 2024-09-16 09:53:00 字数 61 浏览 16 评论 0原文

使用 Delphi 我想向边框图标按钮添加另一个按钮;关闭、最大化、最小化。关于如何做到这一点有什么想法吗?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

泡沫很甜 2024-09-23 09:53:00

在 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 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.

小瓶盖 2024-09-23 09:53:00

Chris Rolliston 撰写了有关 在 Vista 和 Windows 7 上创建自定义标题栏

他还写了一篇后续文章 并在 CodeCentral 上发布了示例代码。

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.

枉心 2024-09-23 09:53:00

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文