国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

開發(fā)一個密碼查看器

2019-11-18 18:22:27
字體:
供稿:網(wǎng)友

現(xiàn)在有很多軟件都有密碼輸入對話框。上面顯示的是*標識符。如果想查看其字符串并不難。下面我們就用delphi使用API函數(shù)來開發(fā)一個查看其密碼字符的程序吧。

功能:當(dāng)鼠標移動到密碼處就會在程序的指定地方顯示其字符串。

問題一:當(dāng)鼠標移動到密碼對話框處時查找出此處的控件句柄。這樣才可以對這個對象進行操作.具體實現(xiàn)如下:

function gethwnd(): thandle;
var
  hwnd: thandle;
  wndpoint: tpoint;
begin
  try
    GetCursorPos(wndpoint); //獲取鼠標指針
    hwnd:=WindowFromPoint(wndpoint);
    Result:=wndpoint
  except
    Result:=0;
  end;
end;

問題二: 根據(jù)獲取的句柄得到此對象的密碼字符。具體實現(xiàn)如下:

function getpass(var hwnd: thandle): string;
var
  passbuf: integer;
  passlong: longint;
  passText: PChar;
begin
  passlong:=SendMessage(hwnd,WM_GETTEXTLENGTH,0,0)+1; //獲取此對象的長度
  GetMem(passText,passlong); //開辟一個內(nèi)存區(qū)。存放數(shù)據(jù)長度為passlong
  passbuf:=LongInt(passtext); //獲取此數(shù)據(jù)區(qū)的首地址
  SendMessage(hwnd,WM_GETTEXT,passlong,passbuf); //發(fā)送消息讓此對象將密碼數(shù)據(jù)存入首地址為passbuf的數(shù)據(jù)區(qū)。存入長度為passlong
  result:=passtext;
end;

這樣主要問題都解決了。還可以使用GetClassName,GetWindowText等API函數(shù)將此對象的類、標題等都讀出來。以下是源代碼,在delphi6.0+winXP測試通過,僅供參考。


{-----------------------------pas內(nèi)容--------------------------------------}
unit getwnd;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Menus;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Timer1: TTimer;
    Label5: TLabel;
    Label6: TLabel;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    Shape1: TShape;
    Shape2: TShape;
    Shape3: TShape;
    Shape4: TShape;
    N2: TMenuItem;
    PRocedure Timer1Timer(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormCreate(Sender: TObject);
    procedure N2Click(Sender: TObject);
  private
    { Private declarations }
  public
     procedure Createparams(Var Params:TCreateParams);override;
    { Public declarations }
  end;

var
  Form1: TForm1;
  hwnd,htemp:THandle;
  point,mouse:TPoint;
  wndcaption:array[0..255] of char;
  wndclass:array[0..255] of char;
  fmove: boolean;

implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
var
  buf: integer;
  ret: longint;
  mText:PChar;
begin
   GetCursorPos(point);
   htemp:=WindowFromPoint(point);
   if hwnd<>htemp then
   begin
      hwnd:=htemp;
      GetClassName(hwnd,wndclass,256);
      GetWindowText(hwnd,wndcaption,256);
      if wndcaption='' then
      begin
         Ret:=SendMessage(hwnd,WM_GETTEXTLENGTH,0,0)+1;
         GetMem(mText,Ret);
         buf:=LongInt(mtext);
         SendMessage(hwnd,WM_GETTEXT,ret,buf);
         label4.Caption:=mText;
      end else
         label4.Caption:=wndcaption;
      label3.Caption:=inttostr(hwnd);
      label6.Caption:=wndclass;
   end;

end;

procedure TForm1.N1Click(Sender: TObject);
begin
  close;
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  fmove:=true;
  mouse.X:=x;
  mouse.Y:=y;
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  fmove:=false;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
   if fmove then
   begin
      top:=top+y-mouse.Y;
      left:=left+x-mouse.X;
   end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   left:=screen.Width-width-3;
   top :=screen.Height-height-34;
end;

procedure TForm1.Createparams(var Params: TCreateParams);
var
  wndParnet: THandle;
begin
  Inherited CreateParams(Params);
  With Params do
  begin
   EXStyle:=ExStyle or WS_EX_TOPMOST OR WS_EX_ACCEPTFILES;
   wndParnet:=GetDesktopWindow;
  end;
end;

procedure TForm1.N2Click(Sender: TObject);
begin
   timer1.Enabled:=not timer1.Enabled;
   if timer1.Enabled then
      n2.Caption:='暫停'
   else
      n2.Caption:='開始';
end;

end.
{-------------------------------------------------------------------------}


{----------------------------dfm內(nèi)容--------------------------------------}
object Form1: TForm1
  Left = 308
  Top = 302
  BorderStyle = bsNone
  Caption = 'xiewh_open'
  ClientHeight = 59
  ClientWidth = 179
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PopupMenu = PopupMenu1
  OnCreate = FormCreate
  OnMouseDown = FormMouseDown
  OnMouseMove = FormMouseMove
  OnMouseUp = FormMouseUp
  PixelsPerInch = 96
  TextHeight = 13
  object Shape1: TShape
    Left = 0
    Top = 0
    Width = 179
    Height = 2
    Align = alTop
    Pen.Color = clBlue
    OnMouseDown = FormMouseDown
    OnMouseMove = FormMouseMove
    OnMouseUp = FormMouseUp
  end
  object Label1: TLabel
    Left = 8
    Top = 11
    Width = 57
    Height = 13
    AutoSize = False
    Caption = #21477#26564#21495#65306
    Transparent = True
  end
  object Label2: TLabel
    Left = 8
    Top = 26
    Width = 64
    Height = 13
    AutoSize = False
    Caption = #26631#39064#21517#65306
    Transparent = True
  end
  object Label3: TLabel
    Left = 56
    Top = 12
    Width = 117
    Height = 13
    AutoSize = False
    Transparent = True
  end
  object Label4: TLabel
    Left = 56
    Top = 25
    Width = 117
    Height = 13
    AutoSize = False
    Transparent = True
  end
  object Label5: TLabel
    Left = 8
    Top = 40
    Width = 56
    Height = 13
    Caption = #31867#12288#21517#65306
    Transparent = True
  end
  object Label6: TLabel
    Left = 56
    Top = 39
    Width = 117
    Height = 13
    AutoSize = False
    Transparent = True
  end
  object Shape2: TShape
    Left = 0
    Top = 0
    Width = 2
    Height = 73
    Pen.Color = clActiveCaption
    Pen.Width = 2
  end
  object Shape3: TShape
    Left = 0
    Top = 57
    Width = 179
    Height = 2
    Align = alBottom
    Pen.Color = clBlue
    Pen.Width = 2
  end
  object Shape4: TShape
    Left = 177
    Top = -1
    Width = 2
    Height = 71
    Pen.Color = clBlue
    Pen.Width = 2
  end
  object Timer1: TTimer
    Interval = 100
    OnTimer = Timer1Timer
    Left = 120
    Top = 32
  end
  object PopupMenu1: TPopupMenu
    Left = 88
    Top = 32
    object N2: TMenuItem
      Caption = #26242#20572
      OnClick = N2Click
    end
    object N1: TMenuItem
      Caption = #36864#20986
      OnClick = N1Click
    end
  end
end

{--------------------------------------------------------------------------}

 

 

 

 

 

 


上一篇:編輯框和位圖按鈕的特殊結(jié)合

下一篇:紙牌控件的編寫(下)

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
學(xué)習(xí)交流
熱門圖片

新聞熱點

疑難解答

圖片精選

網(wǎng)友關(guān)注

主站蜘蛛池模板: 永仁县| 突泉县| 孝感市| 奎屯市| 定州市| 红原县| 肇源县| 广宗县| 大关县| 鹿泉市| 镇赉县| 松江区| 姜堰市| 和龙市| 盐山县| 巴楚县| 区。| 蒲江县| 揭西县| 图片| 渭南市| 苏州市| 克山县| 永兴县| 滦平县| 阿城市| 会昌县| 泌阳县| 喜德县| 庆城县| 简阳市| 中江县| 福建省| 泰兴市| 八宿县| 普陀区| 海安县| 海安县| 舒城县| 福清市| 涿鹿县|