📄 winsubclass.pas
字号:
{ calculate the item sizes }
ClientSize := Point(btn.ClientRect.Right - btn.ClientRect.Left,
btn.ClientRect.Bottom - btn.ClientRect.Top);
// ClientSize := Point(r1.right,r1.bottom);
if Length(Btn.Caption) > 0 then begin
// TextBounds := r1;//Rect(0, 0, r1.right, 0);
TextBounds := Rect(0, 0, clientsize.x,clientsize.y);
DrawText(bg.canvas.handle, PChar(btn.Caption),length(btn.caption), TextBounds,DT_CALCRECT or dt_left);
TextSize := Point(TextBounds.Right - TextBounds.Left, TextBounds.Bottom -
TextBounds.Top);
end else begin
TextBounds := Rect(0, 0, 0, 0);
TextSize := Point(0,0);
end;
if (btn.Glyph <> nil) and (not btn.Glyph.empty) then
GlyphSize := Point(btn.Glyph.Width div btn.NumGlyphs, btn.glyph.Height)
else begin
GlyphSize := Point(0, 0);
DrawCaption(bg.canvas,r1,btn.caption,btn.enabled,false);
aCanvas.draw(rc.left,rc.top,BG);
exit;
end;
{ If the layout has the glyph on the right or the left, then both the
text and the glyph are centered vertically. If the glyph is on the top
or the bottom, then both the text and the glyph are centered horizontally.}
if btn.Layout in [blGlyphLeft, blGlyphRight] then begin
GlyphPos.Y := (ClientSize.y - GlyphSize.Y + 1) div 2;
TextPos.Y := (ClientSize.y - TextSize.Y + 1) div 2;
end else begin
GlyphPos.X := (ClientSize.x - GlyphSize.X + 1) div 2;
TextPos.X := (ClientSize.x - TextSize.X + 1) div 2;
end;
margin:=btn.margin;
spacing:=btn.spacing;
{ if there is no text or no bitmap, then Spacing is irrelevant }
if (GlyphSize.X = 0) or (TextSize.X = 0) then
Spacing := 0;
{ adjust Margin and Spacing }
if btn.Margin = -1 then begin
if Spacing = -1 then begin
TotalSize := Point(GlyphSize.X + TextSize.X, GlyphSize.Y + TextSize.Y);
if btn.Layout in [blGlyphLeft, blGlyphRight] then
Margin := (ClientSize.x - TotalSize.X) div 3
else
Margin := (ClientSize.y - TotalSize.Y) div 3;
Spacing := Margin;
end else begin
TotalSize := Point(GlyphSize.X + Spacing + TextSize.X, GlyphSize.Y +
Spacing + TextSize.Y);
if btn.Layout in [blGlyphLeft, blGlyphRight] then
// Margin := (ClientSize.x - TotalSize.X ) div 2+1
Margin := (r1.right - TotalSize.X ) div 2+1
else
Margin := (ClientSize.y - TotalSize.Y ) div 2+1;
end;
end else begin
if Spacing = -1 then begin
TotalSize := Point(ClientSize.x - (Margin + GlyphSize.X), ClientSize.y -
(Margin + GlyphSize.Y));
if btn.Layout in [blGlyphLeft, blGlyphRight] then
Spacing := (TotalSize.X - TextSize.X) div 2
else
Spacing := (TotalSize.Y - TextSize.Y) div 2;
end;
end;
case btn.Layout of
blGlyphLeft:
begin
GlyphPos.X := Margin;
TextPos.X := GlyphPos.X + GlyphSize.X + Spacing;
DrawStyle:=DT_left;
end;
blGlyphRight:
begin
GlyphPos.X := ClientSize.x - Margin - GlyphSize.X;
TextPos.X := GlyphPos.X - Spacing - TextSize.X;
DrawStyle:=DT_RIGHT;
end;
blGlyphTop:
begin
GlyphPos.Y := Margin;
TextPos.Y := GlyphPos.Y + GlyphSize.Y + Spacing;
DrawStyle:=DT_center;
end;
blGlyphBottom:
begin
GlyphPos.Y := ClientSize.y - Margin - GlyphSize.Y;
TextPos.Y := GlyphPos.Y - Spacing - TextSize.Y;
DrawStyle:=DT_center;
end;
end;
r1:=rect(glyphpos.x,glyphpos.y,0,0);
DrawGlyph(bg.canvas,r1,btn.glyph,j,btn.NumGlyphs);
TextBounds:= rect(textpos.x,textpos.y,textpos.x+TextSize.x,textpos.y+TextSize.y);
bg.Canvas.Font.assign(btn.Font);
// DrawCaption(bg.canvas,TextBounds,btn.caption,btn.enabled,btn.default);
{ bg.canvas.Font.Color := fsd.colors[csButtonText];
if (i=1) then
bg.canvas.Font.Color:= fsd.button.normalcolor2;
if (i=4) then
bg.canvas.Font.Color:= fsd.button.overcolor2;
if (i=2) then
bg.canvas.Font.Color:= fsd.button.downcolor2;
if not btn.enabled then
bg.canvas.Font.Color := clBtnShadow;}
SetBkMode(bg.Canvas.Handle, TRANSPARENT);
DrawText(bg.canvas.Handle, PChar(btn.caption),Length(btn.caption),TextBounds,DrawStyle);
// acanvas.draw(rc.left,rc.top,BG);
aCanvas.draw(rc.left,rc.top,BG);
end;
procedure TSkinControl.DrawCaption(acanvas: TCanvas; rc:TRect;
text:string; enabled,defaulted:boolean;Alignment:word=DT_CENTER);
const
Alignments: array[TAlignment] of Word = (DT_LEFT,DT_RIGHT,DT_CENTER );
var
r1: TRect;
DrawStyle: Longint;
begin
DrawStyle := DT_EXPANDTABS or Alignment;
r1 := rc;
SetBkMode(aCanvas.Handle, TRANSPARENT);
with ACanvas do begin
Brush.Style := bsClear;
font.style:=[];
// Calculate vertical layout
DrawText(ACanvas.Handle,PChar(Text),Length(Text),r1,DrawStyle or DT_CALCRECT or DT_NOCLIP);
if Alignment=dt_center then
OffsetRect(r1, ((rc.right - rc.left) - (r1.right - r1.left)) div 2,
((rc.Bottom - rc.Top) - (r1.Bottom - r1.Top)) div 2-1)
else begin
OffsetRect(r1, 0,((rc.Bottom - rc.Top) - (r1.Bottom - r1.Top)) div 2-1);
r1.Left:=rc.left;r1.right:=rc.Right;
end;
if not enabled then
Font.Color := clBtnShadow;
DrawText(ACanvas.Handle, PChar(Text),-1,r1,DrawStyle);
end;
end;
{ procedure GetImgRect(imgIndex:integer;text:string) ;
var DrawStyle: Longint;
margin:integer;
begin
if imgindex<>-1 then imgrect:=rect(0,0,16,16)
else imgrect:=rect(0,0,0,0);
DrawStyle := DT_EXPANDTABS or DT_SINGLELINE or DT_CENTER;
textrect:=rc;
if imgindex<>-1 then dec(textrect.right,-(2+imgrect.right));
DrawText(Drawtemp.canvas.Handle,PChar(Text),Length(Text),textrect,DrawStyle or DT_CALCRECT or DT_NOCLIP);
margin:=(rc.right-rc.left-imgrect.right-(textrect.right-textrect.left)) div 2;
offsetrect(imgrect,margin,(rc.bottom-rc.top-imgrect.bottom) div 2);
// if (ImgIndex<>-1) then
// ImgList_Draw(imagelist,ImgIndex,ACanvas.handle, r1.Left, r1.Top,ILD_TRANSPARENT);
OffsetRect(textrect,(margin+(textrect.right-textrect.left)) div 2,
((rc.Bottom - rc.Top)-(textrect.Bottom-textrect.Top)) div 2);
end;}
procedure TSkinControl.DrawImgCaption(acanvas: TCanvas; rc:TRect;
ImgList:hImageList;imgIndex:integer;text:string;talign:integer=DT_CENTER);
var
imgrect,textrect,r1,r2: TRect;
DrawStyle: Longint;
h,w,margin:integer;
begin
ImageList_GetIconSize(ImgList,w,h);
if (imgindex<>-1) and (ImgList<>0) then begin
imgrect:=rect(0,0,w,h);
end else begin
imgrect:=rect(0,0,0,0);
w:=0;
end;
DrawStyle := DT_EXPANDTABS or DT_SINGLELINE or DT_CENTER;
textrect:=rc;
if (ImgList<>0) and (imgindex<>-1) then dec(textrect.right,-(2+w));
if Length(Text)>0 then
DrawText(acanvas.Handle,PChar(Text),Length(Text),textrect,DrawStyle or DT_CALCRECT or DT_NOCLIP)
else textrect.right:=textrect.left;
offsetrect(imgrect,rc.left,rc.top);
case talign of
DT_CENTER :
margin:=(rc.right-rc.left-w-(textrect.right-textrect.left)) div 2;
DT_Left :
margin:=2;
DT_right :
margin:=(rc.right-rc.left-w-(textrect.right-textrect.left))-2;
end;
offsetrect(imgrect,margin,(rc.bottom-rc.top-w) div 2);
OffsetRect(textrect,margin+w+1,
((rc.Bottom - rc.Top)-(textrect.Bottom-textrect.Top)) div 2);
if (ImgList<>0) and (ImgIndex<>-1) then
ImageList_Draw(imglist,ImgIndex,ACanvas.handle,
imgrect.Left, imgrect.Top,ILD_TRANSPARENT);
if Length(Text)=0 then exit;
SetBkMode(aCanvas.Handle, TRANSPARENT);
ACanvas.Brush.Style := bsClear;
ACanvas.font.style:=[];
if not enabled then ACanvas.Font.Color := clBtnShadow;
DrawText(ACanvas.Handle, PChar(Text),Length(Text),textrect,DrawStyle);
end;
{procedure TSkinControl.DrawImgCaption(acanvas: TCanvas; rc:TRect;
ImgList:TCustomImageList;imgIndex:integer;
text:string; enabled,default:boolean;Alignment: TAlignment=taCenter);
const
Alignments: array[TAlignment] of Word = (DT_LEFT,DT_RIGHT,DT_CENTER );
var
r1: TRect;
DrawStyle: Longint;
begin
DrawStyle := DT_EXPANDTABS or DT_SINGLELINE or Alignments[Alignment];
r1.Left := rc.Left + 6;
r1.Top := rc.Top + 1;
r1.Right := r1.Left + 16;
r1.Bottom := r1.Top + 16;
if (ImgIndex>-1) and (ImgIndex <ImgList.Count) then
ImgList.Draw(ACanvas, r1.Left, r1.Top, ImgIndex,Enabled);
rc.left:=r1.right;
r1:=rc;
SetBkMode(aCanvas.Handle, TRANSPARENT);
with ACanvas do begin
Brush.Style := bsClear;
// if Default then
// Font.Style := Font.Style + [fsBold];
font.style:=[];
DrawText(Handle,PChar(Text),Length(Text),r1,DrawStyle or DT_CALCRECT or DT_NOCLIP);
OffsetRect(r1, ((rc.right - rc.left) - (r1.right - r1.left)) div 2,
((rc.Bottom - rc.Top) - (r1.Bottom - r1.Top)) div 2);
Font.Color := fsd.colors[csButtonText];
if not enabled then
Font.Color := clBtnShadow;
DrawText(Handle, PChar(Text),Length(Text),r1,DrawStyle);
end;
end;}
procedure TSkinControl.DrawSkinMap( dc:HDC; rc:TRect;
aObject:TdataSkinObject;I,N:integer);
var temp:Tbitmap;
adc:HDC;
begin
if (rc.right<rc.left) or (rc.bottom<rc.top) then exit;
temp:=GetHMap(rc,aobject.map,aobject.r,i,n,aobject.tile);
if aobject.trans=1 then begin
DrawTranmap(DC,rc,temp);
end else
BitBlt(dc,rc.left ,rc.top,rc.right-rc.left,rc.bottom-rc.Top,
temp.Canvas.Handle ,0 ,0 ,Srccopy);
temp.free;
end;
procedure TSkinControl.DrawBuf( dc:HDC; rc:TRect);
begin
// fcanvas.handle:=dc;
// fcanvas.draw(rc.left,rc.top,BG);
BitBlt(dc,rc.left ,rc.top,rc.right-rc.left,rc.bottom-rc.Top,
bg.Canvas.Handle ,0 ,0 ,Srccopy);
end;
procedure TSkinControl.WMPaint(message:TMessage);
var ps: TPaintStruct ;
dc: HDC ;
rc :Trect;
begin
if ( message.wParam=0 ) then begin
DC := BeginPaint(hWnd, ps);
end else begin
DC := message.wParam;
end;
if GetWindowRect( hWnd, rc ) then begin
// GetWindowRect( hWnd, rc );
boundsrect:=rc;
OffsetRect( rc, -rc.left, -rc.top );
// try
Drawcontrol(dc,rc);
// except
// end;
end;
if ( message.wParam=0 ) then
EndPaint(hWnd, ps);
end;
procedure TSkinControl.DrawBMPSkin( abmp:Tbitmap;rc:TRect;aObject:TdataSkinObject;
I,N:integer;trans:integer);
var temp:Tbitmap;
begin
if ((rc.right-rc.left)<0) or ((rc.bottom-rc.top)<0) then exit;
temp:=GetHMap(rc,aobject.map,aobject.r,i,n,aobject.tile);
fillBG(abmp.canvas.handle,rc);
if trans=1 then begin
temp.Transparent:=true;
temp.Transparentcolor:=clFuchsia;
// temp.Transparentcolor:= temp.Canvas.Pixels[0, 0];
end;
abmp.canvas.draw(0,0,temp);
temp.free;
end;
procedure TSkinControl.DrawSkin( rc:TRect;aObject:TdataSkinObject;
I,N:integer;trans:integer);
var temp:Tbitmap;
begin
if ((rc.right-rc.left)<0) or ((rc.bottom-rc.top)<0) then exit;
temp:=GetHMap(rc,aobject.map,aobject.r,i,n,aobject.tile);
fillBG(bg.canvas.handle,rc);
if trans=1 then begin
temp.Transparent:=true;
temp.Transparentcolor:=clFuchsia;
// temp.Transparentcolor:= temp.Canvas.Pixels[0, 0];
end;
bg.canvas.draw(0,0,temp);
temp.free;
end;
procedure TSkinControl.DrawSkinMap1( dc:HDC; rc:TRect;
bmp:Tbitmap;I,N:integer);
var temp:Tbitmap;
w,h,x:integer;
adc:HDC;
acanvas:Tcanvas;
begin
if (rc.right<rc.left) or (rc.bottom<rc.top) then exit;
temp:=Tbitmap.create;
w:=bmp.width div n;
h:=bmp.height;
temp.height:=rc.bottom-rc.top;
temp.width:=rc.right-rc.left;
x:=(i-1)*w;
temp.canvas.copyrect( rect(0,0,rc.right-rc.left,rc.bottom-rc.top),
bmp.canvas,rect(x,0,x+w,h));
acanvas:=Tcanvas.create;
acanvas.handle:=dc;
try
temp.Transparent:=true;
temp.Transparentcolor:=clFuchsia;
// temp.Transparentcolor:=temp.Canvas.Pixels[0, 0];
acanvas.draw(rc.left,rc.top,temp);
finally
temp.free;
acanvas.free;
end;
end;
procedure TSkinControl.DrawSkinMap3( acanvas:Tcanvas; rc:TRect;
bmp:Tbitmap;I,N:integer);
var temp1:Tbitmap;
w,h,x:integer;
begin
if (rc.right<rc.left) or (rc.bottom<rc.top) then exit;
temp1:=Tbitmap.create;
w:=bmp.width div n;
h:=bmp.height;
temp1.height:=rc.bottom-rc.top;
temp1.width:=rc.right-rc.left;
x:=(i-1)*w;
temp1.canvas.copyrect( rect(0,0,rc.right-rc.left,rc.bottom-rc.top),
bmp.canvas,rect(x,0,x+w,h));
temp1.Transparent:=true;
temp1.Transparentcolor:=clFuchsia;
acanvas.draw(rc.left,rc.top,temp1);
temp1.free;
end;
procedure TSkinControl.DrawSkinMap2( dc:HDC; rc:TRect;
bmp:Tbitmap;I,N:integer);
var temp:Tbitmap;
w,h,x:integer;
begin
if (rc.right<rc.left) or (rc.bottom<rc.top) then exit;
temp:=Tbitmap.create;
w:=bmp.width div n;
h:=bmp.height;
temp.height:=rc.bottom-rc.top;
temp.width:=rc.right-rc.left;
x:=(i-1)*w;
temp.canvas.copyrect( rect(0,0,rc.right-rc.left,rc.bottom-rc.top),
bmp.canvas,rect(x,0,x+w,h));
fcanvas.handle:=dc;
temp.Transparent:=true;
temp.Transparentcolor:=clFuchsia;
// temp.Transparentcolor:=temp.Canvas.Pixels[0, 0];
fcanvas.draw(rc.left,rc.top,temp);
temp.free;
end;
{procedure TSkinControl.DrawSkinMap2( dc:HDC; rc:TRect;
bmp:Tbitmap;I,N:integer);
var mask:Tbitmap;
w,h,x:integer;
begin
if (rc.right<rc.left) or (rc.bottom<rc.top) then exit;
mask:=Tbitmap.create;
mask.assign(bmp);
mask.mask(clFuchsia);
w:=bmp.width div n;
h:=bmp.height;
x:=(i-1)*w;
TransparentStretchBlt(dc,rc.left,rc.Top,rc.Right-rc.Left,rc.Bottom-rc.Top,
bmp.Canvas.Handle,x,0,x+w,h,mask.Handle,x,0);
mask.free;
end;}
function TSkinStatusBar.BeforeProc(var Message: TMessage):boolean;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -