首页  编辑  

自画Form边框

Tags: /超级猛料/VCL/Form,窗体/标题栏和边框/   Date Created:

拦截WM_NCPAINT消息即可:

procedure TForm1.WMNCPaint(var Msg: TWMNCPaint);

var

 dc: hDc;

 Pen: hPen;

 OldPen: hPen;

 OldBrush: hBrush;

begin

 inherited;

 dc := GetWindowDC(Handle);

 msg.Result := 1;

 Pen := CreatePen(PS_SOLID, 1, RGB(255, 0, 0));

 OldPen := SelectObject(dc, Pen);

 OldBrush := SelectObject(dc, GetStockObject(NULL_BRUSH));

 Rectangle(dc, 0, 0, Form1.Width, Form1.Height);

 SelectObject(dc, OldBrush);

 SelectObject(dc, OldPen);

 DeleteObject(Pen);

 ReleaseDC(Handle, Canvas.Handle);

end;