哪位大哥可以把 ThemeEngine 的部分功能提取出来,
做成一个组件或者直接发布 PAS 文件也可以。
功能就是和 ThemeEngine 的 TTeForm 一样,
能够在标题栏绘制两个按钮,一个上卷/展开窗体(RollUp);一个用于缩小窗体到托盘区(Minisize to tray);或者还可以加入一个按钮,用于固定窗体在最前面(stay on top) 。
之所以不用 ThemeEngine 原来的是因为原 TTeForm 太杂,造成运行时窗体移动有影像。
小弟自己试了试,不会 :( 惭愧惭愧,因此求救于各位大哥。
谢谢了!
做成一个组件或者直接发布 PAS 文件也可以。
功能就是和 ThemeEngine 的 TTeForm 一样,
能够在标题栏绘制两个按钮,一个上卷/展开窗体(RollUp);一个用于缩小窗体到托盘区(Minisize to tray);或者还可以加入一个按钮,用于固定窗体在最前面(stay on top) 。
之所以不用 ThemeEngine 原来的是因为原 TTeForm 太杂,造成运行时窗体移动有影像。
小弟自己试了试,不会 :( 惭愧惭愧,因此求救于各位大哥。
谢谢了!
//--------------------------------
unit Unit1;interfaceuses
Windows, Buttons, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
TForm1 = 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;implementationconst
htCaptionBtn=htSizeLast+1;{$R *.DFM}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;end.
如果没有记错的话,应该是《Delphi7 编程百例》上面的第三个或第四个例子。
小弟我曾经硬是照着上面的活活的打了一个点!
我也有一份:
在 Delphi 7.0 下面编译通过。
===============================================================================
uses
Buttonsprivate
{ Private declarations }
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;
implementationconst
HtCaptionBtn= HtSizeLast + 1
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 := clBlack ;
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, R.Top, 'New') ;
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('添加您要执行的代码') ;
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 ;