我想使用 Delphi 为边框图标按钮添加另一个按钮;关闭,最大化,最小化。关于如何执行此操作的任何想法?
最佳答案
在 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一个工作示例。
关于windows - 向窗体添加边框图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3612314/