unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TSetPasswordCharThread =
class(TThread)
private
FWindowTitle :
string;
FSecondsToWait : extended;
FPasswordChar : char;
public
constructor Create(AWindowTitle :
string);
procedure Execute;
override;
end;
TForm1 =
class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses dateutils;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
APassword :
string;
begin
APassword := StringOfChar(#32, 10);
// Suche nach dem Fenster über den Titel und Edits mit Passwordchar patchen
TSetPasswordCharThread.Create('
Authentifizierung');
InputQuery('
Authentifizierung', '
Passwort', APassword);
end;
{ TSetPasswordCharThread }
function EnumChildProc(Wnd: hWnd; PwdChar : Longint): BOOL;
stdcall;
var
szFull:
array[0..MAX_PATH]
of Char;
begin
Result := Wnd <> 0;
if Result
then
begin
GetClassName(Wnd, szFull, SizeOf(szFull));
if AnsiUppercase(szFull) = '
TEDIT'
then
SendMessage(Wnd, EM_SETPASSWORDCHAR, PwdChar, 0);
EnumChildWindows(Wnd, @EnumChildProc, PwdChar);
end;
end;
constructor TSetPasswordCharThread.Create(AWindowTitle :
string);
begin
inherited Create(True);
FreeOnTerminate := true;
FWindowTitle := AWindowTitle;
FSecondsToWait := 3;
FPasswordChar := '
*';
Resume;
end;
procedure TSetPasswordCharThread.Execute;
var
StartTime : TDateTime;
HPwdWindow : HWnd;
begin
StartTime := now;
while not Terminated
do
begin
sleep(50);
if (SecondsBetween(now, StartTime) > FSecondsToWait)
then
Terminate;
HPwdWindow := FindWindow(
nil, PAnsiChar(FWindowTitle));
if HPwdWindow > 0
then
begin
EnumChildWindows(HPwdWindow, @EnumChildProc, Ord(FPasswordChar));
Terminate;
end;
end;
end;
end.