procedure TForm1.DrawCaptButton; var xFrame,yFrame,xSize,ySize:Integer; R:TRect; begin xFrame:=GetSystemMetrics(SM_CXFRAME); yFrame:=GetSystemMetrics(SM_CYFRAME); xSize:=GetSystemMetrics(SM_CXSIZE); ySize:=GetSystemMetrics(SM_CYSIZE); //按钮属性调整->> CaptionBtn:=Bounds(Width-xFrame-5*xSize+2,yFrame+2,xSize+13,ySize-4); Canvas.Handle:=GetWindowDC(Self.Handle); Canvas.Font.Name:='宋体'; Canvas.Font.Color:=clBlue; Canvas.Pen.Color:=clYellow; Canvas.Brush.Color:=clBtnFace; try DrawButtonFace(Canvas,CaptionBtn,1,bsAutoDetect,False,False,False); R:=Bounds(Width-xFrame-5*xSize+3,yFrame+3,xSize+10,ySize-7); with CaptionBtn do Canvas.TextRect(R,R.Left+2,R.Top,'TEST'); finally ReleaseDC(Self.Handle,Canvas.Handle); Canvas.Handle:=0; end; end;
procedure TForm1.WMNCActivate(var Msg: TWMNCActivate); begin inherited; DrawCaptButton; end;
procedure TForm1.WMNCHitTest(var Msg: TWMNCHitTest); begin inherited; with Msg do if PtInRect(CaptionBtn,Point(xPos-Left,yPos-Top)) then Result:=htCaptionBtn; end;
procedure TForm1.WMNCLButtonDown(var Msg: TWMNCLButtonDown); begin inherited; if(Msg.HitTest=htCaptionBtn)then showmessage('good'); end;
procedure TForm1.WMNCPaint(var Msg: TWMNCPaint); begin inherited; DrawCaptButton; end;
procedure TForm1.WMSetText(var Msg: TWMSetText); begin inherited; DrawCaptButton; end;
procedure TForm1.FormResize(Sender: TObject); begin Perform(WM_NCACTIVATE,Word(Active),0); end;