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

📄 winsubclass.pas

📁 这是VCLSKIN v4.22 的所有的源代码
💻 PAS
📖 第 1 页 / 共 5 页
字号:
@@hasIndex:
        MOV     EDI,[ESI].TPropInfo.SetProc
        CMP     [ESI].TPropInfo.SetProc.Byte[3],$FE
        JA      @@isField
        JB      @@isStaticMethod

@@isVirtualMethod:
        MOVSX   EDI,DI
        ADD     EDI,[EAX]
        CALL    DWORD PTR [EDI]
        JMP     @@exit

@@isStaticMethod:
        CALL    EDI
        JMP     @@exit

@@isField:
  AND  EDI,$00FFFFFF
  ADD  EAX,EDI
  MOV  EDX,ECX
  CALL  AssignWideStr

@@exit:
        POP     EDI
        POP     ESI
end;
{$ENDIF}

function  GetStringProp(control: TObject;aprop:string):widestring;
var PropInfo:PPropInfo;
    s:string;
begin
   result:='';
   if  control<>nil then begin
      PropInfo:=GetPropInfo(control,aprop);
      if PropInfo<>nil then  begin
        case PropInfo^.PropType^.Kind of
          tkWString: result := GetWideStrProp(control,PropInfo);
          else  result:=StrToWideStr(GetStrProp(control,PropInfo));
        end;
      end;
   end;
end;

function  GetControlCaption(control: TACControl):widestring;
var PropInfo:PPropInfo;
    s:string;
    aprop:string;
begin
   result:='';
   aprop:='Caption';
   if  control<>nil then begin
      PropInfo:=GetPropInfo(control,aprop);
      if PropInfo<>nil then  begin
        case PropInfo^.PropType^.Kind of
          tkWString: result := control.caption;
          else  result:=StrToWideStr(control.caption);
        end;
      end;
   end;
end;

function  GetObjMethod(control: TObject;aprop:string): TMethod;
var PropInfo:PPropInfo;
begin
//   result:=nil;
   if  control<>nil then begin
      PropInfo:=GetPropInfo(control,aprop);
      if PropInfo<>nil then  begin
        result:=GetMethodProp(control,PropInfo);
      end;
   end;
end;

function GetObjProp(control: TObject;aprop:string; MinClass: TClass):Tobject;
var PropInfo:PPropInfo;
begin
   result:=nil;
   if  control<>nil then begin
      PropInfo:=GetPropInfo(control,aprop);
      if PropInfo<>nil then  begin
        result:=GetObjectProp(control,PropInfo,MinClass);
      end;
   end;
end;

procedure  SetProperty(control: TObject;aprop,value:string);
var PropInfo:PPropInfo;
begin
   if  control<>nil then begin
      PropInfo:=GetPropInfo(control,aprop);
      if PropInfo<>nil then  begin
         if propinfo^.PropType^.Kind= tkEnumeration then
          SetEnumProp(control,PropInfo,value)
         else if propinfo^.PropType^.Kind= tkInteger then
          SetOrdProp(control,PropInfo,strtoint(value))
         else if propinfo^.PropType^.Kind= tkString then
          SetStrProp(control,PropInfo,value)
         else if propinfo^.PropType^.Kind= tkLString then
          SetStrProp(control,PropInfo,value)
         else if propinfo^.PropType^.Kind= tkWString then
          SetStrProp(control,PropInfo,value);
      end;
   end;
end;

procedure TSkinButton.DoMouseDown(var Message: TWMMouse);
var acontrol:Taccontrol;
    p:Tpoint;
begin
    acontrol:=TACcontrol(control);
    with Message do
      if (acontrol.Width > 32768) or (acontrol.Height > 32768) then begin
        GetCursorPos(p);
        p := acontrol.ScreenToClient(p);
        acontrol.MouseDown(mbLeft, KeysToShiftState(Keys), p.X, p.Y);
//        with acontrol.CalcCursorPos do
//          acontrol.MouseDown(mbLeft, KeysToShiftState(Keys), p.X, p.Y);
      end  else
       acontrol.MouseDown(mbLeft, KeysToShiftState(Keys), Message.XPos, Message.YPos);
end;

{procedure TSkinButton.SetRedraw(b:boolean);
begin
   redraw:=b;
   if b then begin
       KillTimer(hwnd, 1);
       sendmessage(hwnd,WM_SETREDRAW,1,0);
       Application.ProcessMessages;
   end else begin
       KillTimer(hwnd, 1);
       sendmessage(hwnd,WM_SETREDRAW,0,0);
       SetTimer(hwnd, 1, 100, nil);
   end;
end;   }

procedure TSkinButton.SetRedraw(b:boolean);
var dw:dword;
begin
//   redraw:=b;
   dw := GetWindowLong(hwnd, GWL_STYLE);
   if b then begin
      KillTimer(hwnd, 1);
      if redraw then
         dw := dw or WS_VISIBLE;
      redraw:=false;
   end else begin
      KillTimer(hwnd, 1);
      redraw := true;
      dw := dw and not WS_VISIBLE;
      SetTimer(hwnd, 1, 100, nil);
   end;
   SetWindowLong(hwnd, GWL_STYLE, dw);
end; 

function TSkinButton.BeforeProc(var Message: TMessage):boolean;
 var s:string;
     sf: Twinskinform;
begin
  {$IFDEF buttontest}
    s:= MsgtoStr(message);
    if s<>''  then begin
      s:=format('Button %s %1x %s',[caption,hwnd,s]);
      fsd.dodebug(s);
      //skinaddlog(s);
    end;
  {$ENDIF}
{    if message.msg= CM_VISIBLECHANGED then begin
        if message.wParam=0 then begin
            if redraw then setredraw(true);
        end;
        result:=true;
        exit;
    end else if isdefault then begin
       default(message);
       result:=false;
       exit;
    end;  }

    result:=true;
    case message.msg of
    WM_LBUTTONDOWN, WM_LBUTTONDBLCLK:
      begin
       if not Focused then  begin
        SetFocus(hwnd);
       end;
       state:=state+[scDown];
       PaintControl(0);
       result:=false;
       if (kind=0) and (control<>nil) then DoMouseDown(TWMMouse(message));
      end;
 {   WM_LBUTTONUP:
      if scDown in state then begin
         state:=state-[scDown];
         PaintControl(0);
         setredraw(false);
         isdefault:=true;
         sendmessage(hwnd,WM_LBUTTONDOWN,message.WParam,message.LParam);
         sendmessage(hwnd,WM_LBUTTONUP,message.WParam,message.LParam);
         isdefault:=false;
         setredraw(true);
         if IsWindowVisible(hwnd) then
            Invalidate;
         result:=false;
      end;}
{    WM_LBUTTONDOWN, WM_LBUTTONDBLCLK:
      begin
       if not Focused then  begin
        SetFocus(hwnd);
       end;
       state:=state+[scDown];
       setredraw(false);
//       sendmessage(hwnd,WM_SETREDRAW,0,0);
       default(message);
//       sendmessage(hwnd,WM_SETREDRAW,1,0);
       setredraw(true);
       PaintControl(0);
       result:=false;
      end;
    WM_LBUTTONUP:
      if scDown in state then begin
         state:=state-[scDown];
         setredraw(false);
         default(message);
         setredraw(true);
         if IsWindowVisible(hwnd) then
            Invalidate;
         result:=false;
      end;}
    WM_TIMER : begin
         setredraw(true);
         result:=false;
       end;
    WM_ERASEBKGND:begin
         message.Result:=1;
         result:=false;
      end;
    wm_paint: begin
        wmpaint(message);
        result:=false;
      end;
{    wm_enable,CM_ENABLEDCHANGED:begin
        WMEnable(message);
        result:=false;
      end;   }
    else result:=inherited beforeProc(message);
    end;
end;

{function TSkinButton.BeforeProc(var Message: TMessage):boolean;
 var s:string;
     sf: Twinskinform;
begin
    if message.msg= CM_VISIBLECHANGED then begin
        if message.wParam=0 then begin
            if redraw then setredraw(true);
        end;
        result:=true;
        exit;
    end else if isdefault then begin
       default(message);
       result:=false;
       exit;
    end;

    result:=true;
    case message.msg of
    WM_LBUTTONDOWN, WM_LBUTTONDBLCLK:
      begin
       if not Focused then  begin
        SetFocus(hwnd);
       end;
       state:=state+[scDown];
       PaintControl(0);
       result:=false;
      end;
    WM_LBUTTONUP:
      if scDown in state then begin
         state:=state-[scDown];
         PaintControl(0);
         setredraw(false);
         isdefault:=true;
         sendmessage(hwnd,WM_LBUTTONDOWN,message.WParam,message.LParam);
         sendmessage(hwnd,WM_LBUTTONUP,message.WParam,message.LParam);
         isdefault:=false;
         setredraw(true);
         if IsWindowVisible(hwnd) then
            Invalidate;
         result:=false;
      end;
    WM_TIMER : begin
         setredraw(true);
         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.WMEnable(var Message: TMessage);
var dw: dword;
begin
{   dw:=GetWindowLong(hWnd,GWL_STYLE);
   dw := dw and ( not WS_VISIBLE);
   SetWindowLong( hwnd, GWL_STYLE, dw);
   dw := dw or WS_VISIBLE;
   SetWindowLong( hwnd, GWL_STYLE, dw);}
   default(Message);
   Invalidate;
end;

procedure TSkinButton.AfterProc(var Message: TMessage);
var sf:Twinskinform;
    s:string;
begin
    case message.msg of
{     CM_MOUSEENTER:
      if Enabled then begin
        state:=state+[scMouseIn];
        Invalidate;
      end;   
   CM_MOUSELEAVE:
      if Enabled then begin
        state:=state-[scMouseIn];
        state:=state-[scDown];
        Invalidate;
      end;  }

    WM_MOUSEMove:begin
      if enabled and (not (scmousein in state)) then begin
        state:=state+[scMouseIn];
        Invalidate;
      end;
      WinSkinData.DoTrackMouse(hwnd);
      end;
    WM_MOUSELEAVE: begin
//          if (scDown in state) then begin
          state:=state-[scMouseIn];
          state:=state-[scDown];
          invalidate;
//          end;
        end;

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

    WM_SETTEXT: PaintControl(0);
    CM_FOCUSCHANGED : invalidate;
    CM_DIALOGKEY:invalidate;
    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);

⌨️ 快捷键说明

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