zoukankan      html  css  js  c++  java
  • 密码防泄露_子类化

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TMyEdit=class(TEdit)
        private
        public
          procedure DefaultHandler(var Message); override;
      end;
    
      TForm1 = class(TForm)
        edt1: TEdit;
        lbl1: TLabel;
        lbl2: TLabel;
        btn1: TButton;
        lbl3: TLabel;
        lbl4: TLabel;
        procedure FormCreate(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure btn1Click(Sender: TObject);
      private
        { Private declarations }
      public
        myEdit:TMyEdit;
      end;
    
    var
      Form1: TForm1;
    
    
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      myEdit:= TMyEdit.Create(nil);
    
      myEdit.Parent:= Form1;
      myEdit.Left:= edt1.Left;
      myEdit.Top:= lbl2.Top;
      myEdit.Width:= edt1.Width;
      myEdit.PasswordChar:= '#';
      myEdit.Visible:= true;
    end;
    
    procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      if myEdit<>nil then
        FreeAndNil(myEdit);
    end;
    
    
    { TMyEdit }
    
    procedure TMyEdit.DefaultHandler(var Message);
    begin
      //inherited;
      if (csDesigning in ComponentState)or(csCreating in ControlState) then
        inherited
      else
      begin
        with Tmessage(message) do
        begin
          case Msg of
            WM_GETTEXT,EM_SETPASSWORDCHAR:inherited;
          else
            inherited;
          end;
        end;
      end;
    end;
    
    
    procedure TForm1.btn1Click(Sender: TObject);
    var
      pBuffer,pBuffer2:pchar;
      iLen,iLen2:Integer;
    begin
      ilen:= GetWindowTextLength(edt1.Handle);
      GetMem(pBuffer,ilen+1); //ascii码 以 '' 结尾
    
      ilen2:= GetWindowTextLength(myEdit.Handle);
      GetMem(pBuffer2,ilen2+1);
      try
        SendMessage(edt1.Handle,WM_GETTEXT,iLen+1,Integer(pBuffer));
        lbl3.Caption:= StrPas(pBuffer);
    
    
        SendMessage(myEdit.Handle,WM_GETTEXT,iLen2+1,Integer(pBuffer2));
        lbl4.Caption:= StrPas(pBuffer2);
      finally
        FreeMem(pBuffer);
        FreeMem(pBuffer2);
      end;
    end;
    end.
    书搞进脑袋 创新 创造; 积极
  • 相关阅读:
    Bzoj 2820: YY的GCD(莫比乌斯反演+除法分块)
    Cogs 2221. [SDOI2016 Round1] 数字配对(二分图)
    Cogs 750. 栅格网络(对偶图)
    最小环问题
    浅谈卡特兰数
    洛谷 P1744 采购特价商品
    HDU 1212 Big Number
    HDU 2108 Shape of HDU
    HDU 1029 Ignatius and the Princess IV
    HDU 1021 Fibonacci Again
  • 原文地址:https://www.cnblogs.com/tobetterlife/p/12170331.html
Copyright © 2011-2022 走看看