Einzelnen Beitrag anzeigen

Benutzerbild von Union
Union

Registriert seit: 18. Mär 2004
Ort: Luxembourg
3.487 Beiträge
 
Delphi 7 Enterprise
 

Re: Inputbox mit Passwordchar

  Alt 15. Feb 2008, 15:29
Und wenn Du InputQuery unbedingt ohne Änderung nutzen willst, kannst Du die eingesparte Zeit wieder vergeuden indem Du z.B. einen Thread erstellst, der Dir das Edit für die Passworteingabe patcht
Delphi-Quellcode:
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) = 'TEDITthen
         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.
Ibi fas ubi proxima merces
sudo /Developer/Library/uninstall-devtools --mode=all
  Mit Zitat antworten Zitat