好代码!!!
但点击“最大化”按钮或 移动时,即不断改变窗口时会有不正常现象。
头尾应分别加上一行代码:
procedure TForm1.WMNCPAint(var Mes: TWMNCPaint);
var
ACanvas : TCanvas;
begin
inherited;//////////////////////////////
ACanvas := TCanvas.Create;
try
ACanvas.Handle := GetWindowDC(Form1.Handle);
with ACanvas do begin
Brush.Color := clActiveCaption;
Font.Name := 'Times New Roman';
Font.Size := 10;
Font.Color := clCaptionText;
Font.Style := [fsItalic, fsBold];
TextOut(GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CXBORDER),
Round((GetSystemMetrics(SM_CYCAPTION) - Abs(Font.Height))/2) +1,
caption);/////////////////
end;
finally
ReleaseDC(Form1.Handle, ACanvas.Handle);
ACanvas.Free;
end;
mes.Result:=0; ////////////////////////////////
end;
WM_NCPAINT
An application sends the WM_NCPAINT message to a window when its frame must be painted.
WM_NCPAINT
hrgn = (HRGN) wParam; // handle of update region
Parameters
hrgn
Value of wParam. Handle to the update region of the window. The update region is clipped to the window frame. When wParam is 1, the entire window frame needs to be updated.
This value can be passed to GetDCEx as in the following example.
case WM_NCPAINT:
{
HDC hdc;
hdc = GetDCEx(hwnd, (HRGN)wParam, DCX_WINDOW|DCX_INTERSECTRGN);
// Paint into this DC
ReleaseDC(hwnd, hdc);
}
Return Values
An application returns zero if it processes this message.
Remarks
The DefWindowProc function paints the window frame.
An application can intercept the WM_NCPAINT message and paint its own custom window frame. The clipping region for a window is always rectangular, even if the shape of the frame is altered.