送你个例子unit Unit1;
interfaceuses
Windows, Buttons, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
typeTForm1 = class(TForm)
    procedure FormResize(Sender: TObject);
private
    CaptionBtn : TRect;
    procedure DrawCaptButton;
    procedure WMNCPaint(var Msg : TWMNCPaint); message WM_NCPaint;
    procedure WMNCActivate(var Msg : TWMNCActivate); message WM_NCACTIVATE;
    procedure WMSetText(var Msg : TWMSetText); message WM_SETTEXT;
    procedure WMNCHitTest(var Msg : TWMNCHitTest); message WM_NCHITTEST;
    procedure WMNCLButtonDown(var Msg : TWMNCLButtonDown); message WM_NCLBUTTONDOWN;
public
{ Public declarations }
end;var
Form1: TForm1;
implementation
const
htCaptionBtn = htSizeLast + 1;
{$R *.DFM}
procedure TForm1.DrawCaptButton;
//file://drawcapbuttton过程的具体实现
var
    xFrame,
    yFrame,
    xSize,
    ySize : Integer;
    R : TRect;
begin
    xFrame := GetSystemMetrics(SM_CXFRAME);
    yFrame := GetSystemMetrics(SM_CYFRAME);
    //file://把窗口的宽度置于变量xFrame,把窗口的高度置于变量yFrame
    xSize:= GetSystemMetrics(SM_CXSIZE);
    ySize:= GetSystemMetrics(SM_CYSIZE);
    // 把标题栏按钮的宽度置于变量xSize,把标题栏按钮的高度置于变量ySize
    CaptionBtn := Bounds(Width - xFrame - 4*xSize + 2,
    yFrame + 2, xSize - 2, ySize - 4);
    //file://定义出新的标题按钮的位置,值放在变量CaptionBtn中
    Canvas.Handle := GetWindowDC(Self.Handle);
    //file://得到窗口的句柄
    Canvas.Font.Name := 'Symbol';
    Canvas.Font.Color := clBlue;
    Canvas.Font.Style := [fsBold];
    Canvas.Pen.Color := clYellow;
    Canvas.Brush.Color := clBtnFace;
    //file://定义画布的字体、画笔、刷子等属性
    try
    DrawButtonFace(Canvas, CaptionBtn, 1, bsAutoDetect, False, False, False);
    //file://在画布上画出定义的按钮
    R := Bounds(Width - xFrame - 4 * xSize + 2,
    yFrame + 3, xSize - 6, ySize - 7);
    //file://在新按钮上画出一个小矩形
    with CaptionBtn do
    Canvas.TextRect(R, R.Left + 2, R.Top - 1, 'W');
    //file://在上面画出的小矩形上填写一个字符'w'字符
    finally
    ReleaseDC(Self.Handle, Canvas.Handle);
    Canvas.Handle := 0;
    //file://容错处理,如果出现异常,把句柄释放掉
    end;
end;
procedure TForm1.WMNCPaint(var Msg : TWMNCPaint);
//WMNCPaint过程的具体实现,该过程在绘制窗口时被调用
begin
    inherited;//继承默认的消息处理程序
    DrawCaptButton;//对按钮进行重画
end;
procedure TForm1.WMNCActivate(var Msg : TWMNCActivate);
// WMNCActivate过程与WMNCPaint过程实现方法相同,该过程在窗口的非客户区要更改为激活状态或非激活状态时被调用
begin
    inherited;
    DrawCaptButton;
end;
procedure TForm1.WMSetText(var Msg : TWMSetText);
// WMSetText过程与WMNCPaint过程实现方法相同,该过程在设置窗口的文本时被调用
begin
    inherited;
    DrawCaptButton;
end;
procedure TForm1.WMNCHitTest(var Msg : TWMNCHitTest);
//file:// WMNCHitTest过程与WMNCPaint过程实现方法相同,该过程在光标移动或鼠标按钮被按下或鼠标按钮被释放时调用
begin
    inherited;
    with Msg do
    if PtInRect(CaptionBtn, Point(XPos - Left, YPos - Top)) then
    Result := htCaptionBtn;//判断鼠标所在位置是否在新按钮的矩形范围内,如果在返回新按钮的标识值
end;
procedure TForm1.WMNCLButtonDown(var Msg : TWMNCLButtonDown);
// WMNCLButtonDown过程与WMNCPaint过程实现方法相同,当光标处于窗口非客户区范围内鼠标左键被按下时调用该过程
begin
    inherited;
    if (Msg.HitTest = htCaptionBtn) then
    ShowMessage('你点击的是标题栏上的新按钮');
// file://判断被点击的是否是新按钮,如果是显示上面的信息,在这里你可以按你的需要编写程序代码
end;
procedure TForm1.FormResize(Sender: TObject);
begin
    Perform(WM_NCACTIVATE, Word(Active), 0);
    //file://如果窗口大小改变则重画标题栏
end;
end.

解决方案 »

  1.   

    form1.borderstyle:=none;
    没有边框
    然后自己做一个边框,处理鼠标移动消息
    procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift:  TShiftState; X, Y: Integer);
    const 
     SC_DragMove = $F012; // a magic number 
    begin 
     ReleaseCapture; 
     Form1.perform(WM_SysCommand, SC_DragMove, 0);
    end; 
    但是有缺陷,窗体向上不能移出屏幕,需要自己写代码记录鼠标位置。