windows - 向窗体添加边框图标

标签 windows delphi delphi-2007 titlebar custom-titlebar

我想使用 Delphi 为边框图标按钮添加另一个按钮;关闭,最大化,最小化。关于如何执行此操作的任何想法?

最佳答案

在 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一个工作示例。

关于windows - 向窗体添加边框图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3612314/

相关文章:

string - 如何计算两个字符串之间的差异?

delphi - 有没有办法用delphi Windows API获得双击速度?

multithreading - 在 delphi 2007 中启动挂起线程的正确方法是什么?

delphi - 为什么我的程序无法识别映射的 UNC 路径?

不同操作系统上的python ctypes问题

c++ - 如何获取 GPU 信息?

android - Delphi使用facebook登录认证

Delphi - 从类和接口(interface)继承(适配器模式)?

windows - 将非 VCL 窗口添加到 VCL 对齐队列