转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> Delphi程序 >> 正文
开发一个密码查看器         ★★★★

开发一个密码查看器

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1158 更新时间:2009/4/23 18:35:08

现在有很多软件都有密码输入对话框。上面显示的是*标识符。如果想查看其字符串并不难。下面我们就用delphi使用API函数来开发一个查看其密码字符的程序吧。

功能:当鼠标移动到密码处就会在程序的指定地方显示其字符串。

问题一:当鼠标移动到密码对话框处时查找出此处的控件句柄。这样才可以对这个对象进行操作.具体实现如下:

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

问题二: 根据获取的句柄得到此对象的密码字符。具体实现如下:

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); //开辟一个内存区。存放数据长度为passlong
  passbuf:=LongInt(passtext); //获取此数据区的首地址
  SendMessage(hwnd,WM_GETTEXT,passlong,passbuf); //发送消息让此对象将密码数据存入首地址为passbuf的数据区。存入长度为passlong
  result:=passtext;
end;

这样主要问题都解决了。还可以使用GetClassName,GetWindowText等API函数将此对象的类、标题等都读出来。以下是源代码,在delphi6.0+winXP测试通过,仅供参考。


{-----------------------------pas内容--------------------------------------}
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内容--------------------------------------}
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

[1] [2]  下一页


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台