Read out Edit / EditBox from another application even if it says: "*****" (Views: 28)
Problem/Question/Abstract: How to read out Edit / EditBox from another application even if it says: "*****" Answer: unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, ComCtrls; type TForm1 = class(TForm) Timer1: TTimer; Panel1: TPanel; StatusBar1: TStatusBar; // Procedures procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } public { Public declarations } end; var Form1: TForm1; bQuit: Boolean; implementation {$R *.DFM} //-------------------------------------------------------------------- procedure TForm1.FormCreate(Sender: TObject); begin // Init Bo bQuit := False; // Init timer Timer1.Interval := 250; Timer1.Enabled := True; end; //-------------------------------------------------------------------- procedure TForm1.Timer1Timer(Sender: TObject); var pP: TPoint; iX, iY: Integer; iOldX, iOldY: Integer; iL: Integer; aBuf: array[0..255] of Char; hH, hOldH: THandle; hH1: Thandle; begin // Timer off Timer1.Enabled := False; iOldX := 0; iOldY := 0; hOldH := 0; repeat // Let windows do his job(s) Application.ProcessMessages; // Get position of cursor on screen GetCursorPos(pP); // Convert to X and Y value iX := pP.x; iY := pP.y; // Get the handle of the component under the cursor hH := WindowFromPoint(pP); // Get the handle of the child (if any) hH1 := ChildWindowFromPoint(hH, pP); if hH1 <> 0 then hH := hH1; if (iOldX <> iX) or (iOldY <> iY) then if hH <> hOldH then begin if hH <> Panel1.Handle then begin GetClassName(hH, aBuf, SizeOf(aBuf)); Form1.Panel1.Caption := 'Class: ' + StrPas(aBuf); // Show the classname in the label iL := SendMessage(hH, WM_GETTEXT, SizeOf(aBuf), longint(@aBuf)); // If length of line > 0 then show the line in the Label if iL > 0 then Panel1.Caption := 'Text: "' + StrPas(aBuf) + '"'; end else Panel1.Caption := 'Get me the password!'; // Save old x, y, h values hOldH := hH; iOldX := iX; iOldY := iY; end; until bQuit; end; //-------------------------------------------------------------------- procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin // Quit the repeat loop on close bQuit := True; end; //-------------------------------------------------------------------- end. //==================================================================== |