Author: Maarten de Haan
How to read out Edit / EditBox from another application even if it says: "*****"
Answer:
1 unit
2 Unit1;
3
4 interface
5
6 uses
7 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
8 Dialogs, ExtCtrls, StdCtrls, ComCtrls;
9
10 type
11 TForm1 = class(TForm)
12 Timer1: TTimer;
13 Panel1: TPanel;
14 StatusBar1: TStatusBar;
15 // Procedures
16 procedure FormCreate(Sender: TObject);
17 procedure Timer1Timer(Sender: TObject);
18 procedure FormClose(Sender: TObject; var Action: TCloseAction);
19
20 private
21 { Private declarations }
22 public
23 { Public declarations }
24 end;
25
26 var
27 Form1: TForm1;
28 bQuit: Boolean;
29
30 implementation
31
32 {$R *.DFM}
33
34 //--------------------------------------------------------------------
35
36 procedure TForm1.FormCreate(Sender: TObject);
37
38 begin
39 // Init Bo
40 bQuit := False;
41
42 // Init timer
43 Timer1.Interval := 250;
44 Timer1.Enabled := True;
45
46 end;
47 //--------------------------------------------------------------------
48 procedure TForm1.Timer1Timer(Sender: TObject);
49
50 var
51 pP: TPoint;
52 iX, iY: Integer;
53 iOldX, iOldY: Integer;
54 iL: Integer;
55 aBuf: array[0..255] of Char;
56 hH, hOldH: THandle;
57 hH1: Thandle;
58
59 begin
60 // Timer off
61 Timer1.Enabled := False;
62 iOldX := 0;
63 iOldY := 0;
64 hOldH := 0;
65 repeat
66 // Let windows do his job(s)
67 Application.ProcessMessages;
68 // Get position of cursor on screen
69 GetCursorPos(pP);
70 // Convert to X and Y value
71 iX := pP.x;
72 iY := pP.y;
73 // Get the handle of the component under the cursor
74 hH := WindowFromPoint(pP);
75 // Get the handle of the child (if any)
76 hH1 := ChildWindowFromPoint(hH, pP);
77 if hH1 <> 0 then
78 hH := hH1;
79
80 if (iOldX <> iX) or (iOldY <> iY) then
81 if hH <> hOldH then
82 begin
83 if hH <> Panel1.Handle then
84 begin
85 GetClassName(hH, aBuf, SizeOf(aBuf));
86 Form1.Panel1.Caption := 'Class: ' + StrPas(aBuf);
87 // Show the classname in the label
88 iL := SendMessage(hH, WM_GETTEXT, SizeOf(aBuf), longint(@aBuf));
89 // If length of line > 0 then show the line in the Label
90 if iL > 0 then
91 Panel1.Caption := 'Text: "' + StrPas(aBuf) + '"';
92 end
93 else
94 Panel1.Caption := 'Get me the password!';
95
96 // Save old x, y, h values
97 hOldH := hH;
98 iOldX := iX;
99 iOldY := iY;
100 end;
101 until bQuit;
102 end;
103 //--------------------------------------------------------------------
104
105 procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
106
107 begin
108 // Quit the repeat loop on close
109 bQuit := True;
110 end;
111 //--------------------------------------------------------------------
112 end.
113 //====================================================================
|