【问题标题】:Add a border icon to the form向表单添加边框图标
【发布时间】:2011-04-06 10:53:29
【问题描述】:

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

【问题讨论】:

    标签: windows delphi delphi-2007 titlebar custom-titlebar


    【解决方案1】:

    Chris Rolliston 写了一篇关于creating a custom title bar on Vista and Windows 7 的详细博客。

    他还写了一个follow up article,并在CodeCentral上发布了示例代码。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        在 Windows Aero 之前,这很容易做到。您只需收听WM_NCPAINTWM_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

        【讨论】:

          猜你喜欢
          • 2016-03-25
          • 2012-08-26
          • 1970-01-01
          • 2017-06-28
          • 1970-01-01
          • 1970-01-01
          • 2018-01-14
          • 2022-12-01
          • 2019-02-15
          相关资源
          最近更新 更多