拿这个代码去试试:
unit demofrm;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
private
procedure WMNCPAint(var Msg : TMessage); message WM_NCPAINT;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.WMNCPAint(var Msg : TMessage);
var
ADC : HDC;
ARgn: HRGN;
lb: TLOGBRUSH;
hBr: HBRUSH;
ARect: TRect;
AText: string;
OldBr: HBRUSH;
begin
ARect := Rect(2, 2, 120, 20);
ARgn := CreateRectRgn(ARect.Left , ARect.Top , ARect.Right , ARect.Bottom );
ADC := GetWindowDC(Handle);
lb.lbStyle := BS_SOLID;
lb.lbColor := clRed;
lb.lbHatch := 0;
hBr := CreateBrushIndirect(lb);
try
OldBr := SelectObject(ADC, hBr);
FillRgn(ADC, ARgn, hBr);
AText := 'Hello, baby!';
DrawText(ADC, PChar(AText), Length(AText), ARect, DT_SINGLELINE or DT_VCENTER or DT_CENTER);
finally
SelectObject(ADC, OldBr);
DeleteObject(hBr);
end;
Msg.Result := 0;
end;
end.