delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback



Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi








Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (4)


How to read the text of a TEdit from another applicationFormat this article printer-friendly!Bookmark function is only available for registered users!
Even if you only see **********
Product:
Delphi 5.x (or higher)
Category:
Win API
Skill Level:
Scoring:
Last Update:
02/28/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet EM_GETLINE EM_LINEINDEX EM_LINELENGTH EM_GETFIRSTVISIBLELINE EM_GETPASSWORDCHAR EM_SETPASSWORDCHAR LB_GETTEXT CB_GETLBTEXT PassWordChar CB_GETLBTEXTLEN SendMessage Encryption PassWord ES_PASSWORD WM_GETTEXT
Times Scored:
3
Visits:
6057
Uploader: Maarten de Haan
Company: TNO Industrial Technology
Reference: MicroSoft MSDN library
 
Question/Problem/Abstract:
With this method you can read a TEdit from another application. For instance the TEdit containing the internet address from MS-IE.
Answer:



(* You'll need a form with a TEdit, a Timer and a Label on it.
1) Open two instances of this application.
2) Enter a text in the TEdit of application 1.
3) Just look at what you see in the label of application 2 if you go with the mouse over the TEdit of application 1
Do you get the point? *)

// Modified 28/02/2002
// Added WM_GETTEXT
// By WM_GETTEXT f.i. the passwordbox of Excel can be read
// Now the application also reads EditBox (not only TEdit, Edit and RichEdit)
// Added ChildWindowFromPoint (thanks to Scalabium)

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Timer1: TTimer;
    Procedure FormCreate(Sender : TObject);
    Procedure FormClose(Sender: TObject; var Action: TCloseAction);
    Procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Bo     : Boolean;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.PasswordChar := '*';
Bo := False;
Timer1.Interval := 250;
Timer1.Enabled := True;
Edit1.Text := '';
Label1.Caption := '';
end;

procedure TForm1.Timer1Timer(Sender: TObject);

Var
   p             : TPoint;
   x,y,oldx,oldy : Integer;
   s             : String;
   b             : Array[0..255] of Char;
   i,j,l         : Integer;
   h,oldh, h1    : Thandle;

begin
Timer1.Enabled := False;
oldx := 0;
oldy := 0;
oldh := 0;
Repeat
   Application.ProcessMessages;
   GetCursorPos(p);
   x := p.x;
   y := p.y;
   h := WindowFromPoint(p);
   h1 := ChildWindowFromPoint(h,p);
   If h1 <> 0 then
      h := h1;

   if (oldx <> x) or (oldy <> y) then
      if h <> oldh then
         Begin
         FillChar(b,255,#0);
         b[0] := #255;
         j := integer(@b);
         i := SendMessage(h,EM_GETPASSWORDCHAR,0,0); // no encryption
         l := SendMessage(h,EM_GETLINE,0,j); // get line
         If l = 0 then
            SendMessage(h,WM_GETTEXT,sizeof(b),j);
         SendMessage(h,EM_SETPASSWORDCHAR,i,0); // encrypt back
         s := StrPas(b);
         If s <> '' then
            Label1.Caption := s; // show unencrypted line
         oldh := h;
         oldx := x;
         oldy := y;
         End;

Until Bo;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Bo := True;
end;

end.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
few notes
    Mike Shkolnik (Feb 27 2002 11:28AM)

1. this code couldn't work when edit is inside of some frame. You must use ChildWindowFromPoint for correct window detection (not only WindowFromPoint)

2. this code couldn't work in Win2000+XP at all

PS: some time ago I wrote the similar ShowPW tool which allow to take a password from external windows too. Check it if you like;-)

With best regards, Mike Shkolnik
E-Mail: mshkolnik@scalabium.com
        mshkolnik@yahoo.com
WEB: http://www.scalabium.com

Respond

RE: few notes
Maarten de Haan (Feb 27 2002 12:45PM)

Thank you very much for your help! I'll try to implement your suggestions!
Greetings, MdH
Respond

passwords and TEdit
    EberSys (Feb 26 2002 5:22PM)

...has some bugs, like it will crash very often... but, is quite interesting... a while ago many password crackers used this technique, this article also shows you why is not recommended to save passwords in a TEdit, when you need to, save/encrypt the password in some variable and put some other characters on the TEdit
salu2

EberSys
Respond

RE: passwords and TEdit
Maarten de Haan (Feb 26 2002 7:58PM)

This method works very fine under WinNT. I know it doesn't work very fine under W95.
It's very easy to criticize. But where are your improvements?


Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


   


  Community Ad of
A. B. Talal
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)