⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 winsubclass.pas

📁 一个仓库管理软件系统
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    s:= MsgtoStr(message);
    if s<>''  then begin
      s:=format('Button %s %1x %s',[caption,hwnd,s]);
      skinaddlog(s);
    end;
  {$ENDIF}

    result:=true;
    case message.msg of
    WM_LBUTTONDOWN, WM_LBUTTONDBLCLK:
      begin
       if not Focused then  begin
        SetFocus(hwnd);
//        if not Focused then Exit;
       end;
       state:=state+[scDown];
       PaintControl(0);
       result:=false;
      end;
    WM_ERASEBKGND:begin
         Message.Result := 1;
         result:=false;
      end;
    wm_paint: begin
        wmpaint(message);
        result:=false;
      end;

    else result:=inherited beforeProc(message);
    end;
end;

procedure TSkinButton.AfterProc(var Message: TMessage);
var sf:Twinskinform;
begin
    case message.msg of
    CM_MOUSEENTER:
      if Enabled then begin
        state:=state+[scMouseIn];
        Invalidate;
        sf:=Twinskinform(skinform);
        if (sf.activeskincontrol<>self) then
           sf.activeskincontrol:=self;
      end;
    CM_MOUSELEAVE:
      if Enabled then begin
        state:=state-[scMouseIn];
        state:=state-[scDown];
        Invalidate;
        sf:=Twinskinform(skinform);
        if (sf.activeskincontrol=self) then
           sf.activeskincontrol:=nil;
      end;

    WM_MOUSEMove:
      if not (scmousein in state) then begin
        state:=state+[scMouseIn];
        sf:=Twinskinform(skinform);
        if (sf.activeskincontrol<>nil) and
           (sf.activeskincontrol<>self) then
            sf.activeskincontrol.mouseleave;
        if (sf.activeskincontrol<>self) then begin
           Invalidate;
           sf.activeskincontrol:=self;
        end;
      end;

    WM_LBUTTONUP:
      if scDown in state then begin
         state:=state-[scDown];
         Invalidate;
         if control<>nil then
           TACcontrol(control).Click
//           postMessage(getparent(hwnd),WM_COMMAND,BN_CLICKED,hWnd)
         else postMessage(getparent(hwnd),WM_COMMAND,BN_CLICKED*$100+GetDlgCtrlID(hwnd),hWnd);
      end;

    WM_KEYDOWN:
      if Message.WParam = VK_SPACE then begin
       state:=state+[scDown];
       Invalidate;
      end;

    WM_KEYUP:
      if Message.WParam = VK_SPACE then begin
        state:=state-[scDown];
        Invalidate;
      end;
    else inherited AfterProc(message);
    end;
end;

{procedure TSkinButton.DrawControl( dc:HDC; rc:TRect);
var i:integer;
    r1:Trect;
    acolor:Tcolor;
    bfont,cfont:Hfont;
    temp:Tbitmap;
begin
    if fsd.button=nil then exit;
    if fsd.Button.map.empty then exit;
    i:=1;

    temp:=Tbitmap.create;

    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);
    temp.width:=r1.right;
    temp.height:=r1.bottom;
    DrawBMPSkin(temp,r1,fsd.button,i,5,fsd.button.Trans);

    bfont:=sendmessage(hwnd,wm_getfont,0,0);
    cfont:=selectobject(temp.canvas.handle,bfont);

    SetTextColor(temp.canvas.handle,fsd.colors[csButtonText]);
    if (i=1) then
       SetTextColor(temp.canvas.handle,fsd.button.normalcolor2);
    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;
end;

destructor TSkinButton.Destroy;
begin
   if btemp<>nil then btemp.free;
   btemp:=nil;
   inherited destroy;
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;
begin
   DrawStyle := DT_EXPANDTABS or Alignment;
   r1 := rc;
   SetBkMode(aCanvas.Handle, TRANSPARENT);
   with ACanvas do begin
     Tnt_DrawTextW(ACanvas.Handle, caption,r1,DrawStyle or DT_CALCRECT or DT_NOCLIP);
     //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);
   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;
begin
    if fsd.button=nil then exit;
    if fsd.Button.map.empty then exit;
    i:=1;

    style:=GetWindowLong(hWnd,GWL_STYLE);
    isdefault := ( style and BS_DEFPUSHBUTTON ) = BS_DEFPUSHBUTTON ;
    Focused := (GetFocus= hWnd);
    enabled := ( style and WS_DISABLED )=0;

    if (control<>nil) then
      caption := GetStringProp(control,'Caption')
    else
      caption:=getformcaption(hwnd);

    if focused then i:=4;
    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;

    FillBG(btemp.canvas.handle,r1);
    DrawSkinMap( btemp.canvas.handle,r1,fsd.button,I,5);

    if control<>nil then begin
      font := Tfont(GetObjProp(control,'Font',Tfont));
      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,fsd.colors[csButtonText]);
    if (i=1) then
       SetTextColor(btemp.canvas.handle,fsd.button.normalcolor2);
    if (i=4) then
       SetTextColor(btemp.canvas.handle,fsd.button.overcolor2);
    if (i=2) then
       SetTextColor(btemp.canvas.handle,fsd.button.downcolor2);
    if not enabled then
      SetTextColor(btemp.canvas.handle,clGray);
    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;}

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:string;
    bglyph:Tbitmap;
    bglist:Timagelist;
    imageindex,disabledindex:integer;
begin
    if fsd.button=nil then exit;
    if fsd.Button.map.empty then exit;
    DrawStyle:=DT_LEFT;

    Focused := (GetFocus= hWnd);
    style := GetWindowLong(hWnd,GWL_STYLE);
    enabled := ( style and WS_DISABLED )=0;
//    caption:=getformcaption(hwnd);
    if control<>nil then
       caption := GetStringProp(control,'Caption')
    else
       caption:=getformcaption(hwnd);
//    btn:=TBitBtn(control);
//    if btn.default then i:=5;
    s:=lowercase(GetEnumProperty(control,'Default'));

    i:=1;
    if s='true' then i:=5;
    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;

    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);

//    DrawSkin(r1,fsd.button,i,fsd.button.frame,fsd.button.Trans);
    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);

  if Length(Caption) > 0 then  begin
    TextBounds := r1;//Rect(0, 0, r1.right, 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);
    TextSize := Point(TextBounds.Right - TextBounds.Left, TextBounds.Bottom -
      TextBounds.Top);
  end  else  begin
    TextBounds := Rect(0, 0, 0, 0);
    TextSize := Point(0,0);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -