📄 winsubclass.pas
字号:
if (i=4) then
SetTextColor(temp.canvas.handle,fsd.button.overcolor2);
if (i=2) then
SetTextColor(temp.canvas.handle,fsd.button.downcolor2);
if not enabled then
SetTextColor(temp.canvas.handle,COLORREF(clBtnShadow));
DrawCaption(temp.canvas,r1,caption,enabled,false);
// DrawBuf( dc,rc);
BitBlt(dc,rc.left ,rc.top,rc.right-rc.left,rc.bottom-rc.Top,
temp.Canvas.Handle ,0 ,0 ,Srccopy);
selectobject(temp.canvas.handle,cfont);
temp.Free;
end;}
constructor TSkinButton.Create(AOwner: TComponent);
begin
inherited create(aowner);
btemp:=Tbitmap.create;
trans:=false;
isdefault:=false;
end;
destructor TSkinButton.Destroy;
begin
if btemp<>nil then btemp.free;
btemp:=nil;
inherited destroy;
end;
Procedure TSkinButton.Init(sf:Tcomponent;sd:TSkinData;acanvas:TCanvas;acolor:boolean=false);
var s:string;
begin
inherited init(sf,sd,acanvas,acolor);
kind :=0;
s:=lowercase(control.classname);
if pos('trz',s)=1 then kind:=1;
if pos('tel',s)=1 then kind:=1;
if (control.Tag=5555) or (xoTransparent in fsd.options) then
trans:=true;
end;
procedure TSkinButton.DrawBtnText(acanvas: TCanvas; rc:TRect;
text:String;Alignment:word=DT_CENTER);
const
Alignments: array[TAlignment] of Word = (DT_LEFT,DT_RIGHT,DT_CENTER );
var
r1: TRect;
DrawStyle: Longint;
s,s1:string;
begin
DrawStyle := DT_EXPANDTABS or Alignment or dt_WordBreak;
{ if multiline then begin
DrawStyle := DrawStyle or dt_WordBreak;
s:=WideStringToStringEx(caption);
s:=stringreplace(s,'||',#13#10,[rfReplaceAll]);
caption := StrToWideStr(s);
end;}
s:= StrToWideStr('||');
s1:= StrToWideStr(#13#10);
caption := StringReplaceW(caption,s,s1);
r1 := rc;
inflaterect(r1,-2,-2);
SetBkMode(aCanvas.Handle, TRANSPARENT);
with ACanvas do begin
Tnt_DrawTextW(ACanvas.Handle, caption,r1,DrawStyle or DT_CALCRECT or DT_NOCLIP);
offsetrect(r1,-r1.Left,-r1.Top);
drawstyle:=checkBiDi(drawStyle);
//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;
// DrawText(ACanvas.Handle, PChar(Text),-1,r1,DrawStyle);
Tnt_DrawTextW(ACanvas.Handle, caption,r1,DrawStyle);
SetBkMode(aCanvas.Handle, OPAQUE);
if focused and not (xoNoFocusRect in fsd.Options) then begin
InflateRect(r1,2,2);
DrawFocusRect(r1);
end;
end;
end;
procedure TSkinButton.DrawControl( dc:HDC; rc:TRect);
var i:integer;
r1:Trect;
acolor:Tcolor;
bfont,cfont:Hfont;
style:dword;
isdefault:boolean;
font:Tfont;
s:string;
begin
if fsd.button=nil then exit;
if fsd.Button.map.empty then exit;
i:=1;
style:=GetWindowLong(hWnd,GWL_STYLE);
Focused := (GetFocus= hWnd);
enabled := ( style and WS_DISABLED )=0;
// dw:= ( style and $0f );
// isdefault := (( style and $0f ) = BS_DEFPUSHBUTTON );
multiline := false;
if (control<>nil) then begin
caption := GetStringProp(control,'Caption');
s := lowercase(GetEnumProperty(control,'MultiLine'));
if s='true' then multiline := true;
end else
caption:=getformcaption(hwnd);
if focused then i:=5;
if isdefault then i:=5;
if (scDown in state) then i:=2
else if (scMouseIn in state) then i:=4;
if not enabled then i:=3;
r1:=rc;
offsetrect(r1,-r1.left,-r1.top);
btemp.width:=r1.right;
btemp.height:=r1.bottom;
if trans then
DrawParentImage(control,btemp.canvas.handle,true)
else
fillBG(btemp.canvas.handle,r1);
{ if (not (xoTransparent in fsd.options)) or (control=nil) then begin
fillBG(btemp.canvas.handle,r1);
end
else if control<>nil then
DrawParentImage(control,btemp.canvas.handle,true);}
//else FillBG(btemp.canvas.handle,r1); }
DrawSkinMap( btemp.canvas.handle,r1,fsd.button,I,fsd.Button.frame);
if control<>nil then begin
font := Tfont(GetObjProp(control,'Font',Tfont));
if font<>nil then btemp.canvas.font.assign(font);
if (i=1) and (fsd.button.newnormal) then
btemp.canvas.Font.Color:= fsd.button.normalcolor2;
if (i=4) and (fsd.button.newover) then
btemp.canvas.Font.Color:= fsd.button.overcolor2;
if (i=2) and (fsd.Button.newdown) then
btemp.canvas.Font.Color:= fsd.button.downcolor2;
if not enabled then
btemp.canvas.Font.Color := clBtnShadow;
end else begin
bfont:=sendmessage(hwnd,wm_getfont,0,0);
cfont:=selectobject(btemp.canvas.handle,bfont);
SetTextColor(btemp.canvas.handle,ColorToRGB(fsd.colors[csButtonText]));
if (i=1) and (fsd.button.newnormal) then
SetTextColor(btemp.canvas.handle,ColorToRGB(fsd.button.normalcolor2));
// if ((i=4) or (i=5)) and (fsd.button.newover) then
if (i=4) and (fsd.button.newover) then
SetTextColor(btemp.canvas.handle,ColorToRGB(fsd.button.overcolor2));
if (i=2) and (fsd.Button.newdown) then
SetTextColor(btemp.canvas.handle,ColorToRGB(fsd.button.downcolor2));
if not enabled then
SetTextColor(btemp.canvas.handle,ColorToRGB(clBtnShadow));
end;
DrawBtnText(btemp.canvas,r1,caption);
// Bitmapdraw(dc,rc,btemp);
BitBlt(dc,rc.left ,rc.top,rc.right-rc.left,rc.bottom-rc.Top,
btemp.Canvas.Handle ,0 ,0 ,Srccopy);
selectobject(btemp.canvas.handle,cfont);
{$IFDEF buttontest}
skinaddlog(format('Button Draw %s %1x %1x',[caption,hwnd,dc]));
{$ENDIF}
end;
{procedure TSkinButton.DrawControl( dc:HDC; rc:TRect);
var i:integer;
r1:Trect;
acolor:Tcolor;
bfont,cfont:Hfont;
begin
if fsd.button=nil then exit;
if fsd.Button.map.empty then exit;
i:=1;
Focused := (GetFocus= hWnd);
enabled := (GetWindowLong(hWnd,GWL_STYLE) and WS_DISABLED)=0;
caption:=getformcaption(hwnd);
if (caption='') and (control<>nil) then
caption:=Taccontrol(control).caption;
if focused then i:=4;
if (scDown in state) then i:=2
else if (scMouseIn in state) then i:=4;
if not enabled then i:=3;
r1:=rc;
offsetrect(r1,-r1.left,-r1.top);
bg.width:=r1.right;
bg.height:=r1.bottom;
DrawSkin(r1,fsd.button,i,5,fsd.button.Trans);
// DrawSkinMap( dc:HDC; rc:TRect;aObject:TdataSkinObject;I,N:integer)
bfont:=sendmessage(hwnd,wm_getfont,0,0);
cfont:=selectobject(bg.canvas.handle,bfont);
SetTextColor(bg.canvas.handle,fsd.colors[csButtonText]);
if (i=1) then
SetTextColor(bg.canvas.handle,fsd.button.normalcolor2);
if (i=4) then
SetTextColor(bg.canvas.handle,fsd.button.overcolor2);
if (i=2) then
SetTextColor(bg.canvas.handle,fsd.button.downcolor2);
if not enabled then
SetTextColor(bg.canvas.handle,COLORREF(clBtnShadow));
DrawCaption(bg.canvas,r1,caption,enabled,false);
SetBkMode(bg.canvas.handle,OPAQUE);
DrawBuf( dc,rc);
selectobject(bg.canvas.handle,cfont);
end;}
{procedure TButtonGlyph.CalcButtonLayout(Canvas: TCanvas; const Client: TRect;
const Offset: TPoint; const Caption: string; Layout: TButtonLayout; Margin,
Spacing: Integer; var GlyphPos: TPoint; var TextBounds: TRect;
BiDiFlags: LongInt);}
{procedure TSkinBitButton.DrawControl( dc:HDC; rc:TRect);
var btn:TBitBtn;
acolor:Tcolor;
i,n,j:integer;
spacing,margin:integer;
r1,TextBounds:Trect;
Layout: TButtonLayout;
TextPos: TPoint;
GlyphPos, ClientSize, GlyphSize, TextSize: TPoint;
TotalSize: TPoint;
DrawStyle: Longint;
cfont,bfont:Hfont;
begin
if fsd.button=nil then exit;
if fsd.Button.map.empty then exit;
DrawStyle:=DT_LEFT;}
function StringReplaceW(s,s1,s2:widestring):widestring;
var i,p,l:integer;
begin
result:=s;
l:=length(s);
p:=pos(s1,s);
if p>0 then begin
result:=copy(s,1,p-1)+s2+copy(s,p+length(s1),l);
end;
end;
procedure TSkinBitButton.DrawControl( dc:HDC; rc:TRect);
var acolor:Tcolor;
i,j:integer;
r1,TextBounds:Trect;
Layout: TButtonLayout;
NumGlyphs,margin,spacing :integer;
TextPos: TPoint;
GlyphPos, ClientSize, GlyphSize, TextSize: TPoint;
TotalSize: TPoint;
DrawStyle: Longint;
cfont,bfont:Hfont;
font:Tfont;
style : dword;
s,s1:widestring;
bglyph:Tbitmap;
bglist:Timagelist;
imageindex,disabledindex:integer;
isdefault:boolean;
bname:string;
begin
if fsd.button=nil then exit;
if fsd.Button.map.empty then exit;
if Length(PicField)>0 then begin
drawPicControl(dc,rc);
exit;
end;
// DrawStyle:=DT_LEFT;
Focused := (GetFocus= hWnd);
style := GetWindowLong(hWnd,GWL_STYLE);
enabled := ( style and WS_DISABLED )=0;
// caption:=getformcaption(hwnd);
//dw := ( style and $0f );
//isdefault := (dw = BS_DEFPUSHBUTTON );
if control<>nil then
caption := GetStringProp(control,'Caption')
// caption := GetControlCaption(TACControl(control))
else
caption:=getformcaption(hwnd);
// btn:=TBitBtn(control);
// if btn.default then i:=5;
// s:=lowercase(GetEnumProperty(control,'Default'));
i:=1;
if Focused then i:=5;
// if isdefault then i:=5;
if (scDown in state) then i:=2
else if (scMouseIn in state) then i:=4;
if not enabled then i:=3;
case i of
1: j:=1;
2: j:=3;
3: j:=2;
4: j:=1;
else j:=1;
end;
r1:=rc;
offsetrect(r1,-r1.left,-r1.top);
btemp.width:=r1.right;
btemp.height:=r1.bottom;
bfont:=sendmessage(hwnd,wm_getfont,0,0);
cfont:=selectobject(btemp.canvas.handle,bfont);
if trans then
DrawParentImage(control,btemp.canvas.handle,true)
else
fillBG(btemp.canvas.handle,r1);
DrawSkinMap( btemp.canvas.handle,r1,fsd.button,I,fsd.button.frame);
ClientSize := Point(rc.Right - rc.Left,rc.Bottom - rc.Top);
font := Tfont(GetObjProp(control,'Font',Tfont));
bglyph := Tbitmap(GetObjProp(control,'Glyph',Tbitmap));
bglist := Timagelist(GetObjProp(control,'Images',Timagelist));
NumGlyphs := GetIntProperty(control,'NumGlyphs') ;
imageindex := GetIntProperty(control,'ImageIndex') ;
disabledindex := GetIntProperty(control,'DisabledIndex') ;
if NumGlyphs<0 then NumGlyphs:=1;
Margin := GetIntProperty(control,'Margin') ;
Spacing := GetIntProperty(control,'Spacing') ;
s := lowercase(GetEnumProperty(control,'Layout'));
if s='blglyphleft' then layout:=blGlyphLeft
else if s='blglyphright' then layout:=blGlyphRight
else if s='blglyphtop' then layout:=blGlyphTop
else if s='blglyphbottom' then layout:=blGlyphbottom;
if (bGlyph <> nil) and (not bglyph.Empty) then
GlyphSize := Point(bGlyph.Width div NumGlyphs, bglyph.Height)
else if (bglist<>nil) and (imageindex<>-1) then
GlyphSize := Point(bglist.Width, bglist.Height)
else GlyphSize := Point(0, 0);
btemp.canvas.font.assign(font);
DrawStyle := dt_WordBreak;
s:= StrToWideStr('||');
s1:= StrToWideStr(#13#10);
caption := StringReplaceW(caption,s,s1);
TextBounds := r1;//Rect(0, 0, r1.right-GlyphSize.x, 0);
inflaterect(TextBounds,-2,-2);
case Layout of
blGlyphLeft,blGlyphRight: Dec(TextBounds.Right,GlyphSize.X+2);
blGlyphTop,blGlyphBottom: Dec(TextBounds.Bottom,GlyphSize.y+2)
end;
if Length(Caption) > 0 then begin
// TextBounds := r1;//Rect(0, 0, r1.right-GlyphSize.x, 0);
// DrawText(btemp.canvas.handle, PChar(Caption),-1, TextBounds,DT_CALCRECT or dt_left);
Tnt_DrawTextW(btemp.canvas.handle,caption,TextBounds,DT_CALCRECT or dt_left or dt_WordBreak);
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 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 (TextSize.X = 0) or (GlyphSize.X = 0) then
Spacing := 0;
s := lowercase(GetEnumProperty(control,'Alignment'));
if (Margin = -1) or (s='tacenter') then begin
if Spacing = -1 then begin
TotalSize := Point(GlyphSize.X + TextSize.X, GlyphSize.Y + TextSize.Y);
if 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 Layout in [blGlyphLeft, blGlyphRight] then
Margin := (ClientSize.x - TotalSize.X ) div 2
else
Margin := (ClientSize.y - TotalSize.Y ) div 2;
end;
end else begin
if Spacing = -1 then begin
TotalSize := Point(ClientSize.x - (Margin + GlyphSize.X), ClientSize.y -
(Margin + GlyphSize.Y));
if Layout in [blGlyphLeft, blGlyphRight] then
Spacing := (TotalSize.X - TextSize.X) div 2
else
Spaci
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -