whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1547)

Database (90)
Files (137)
Forms (107)
Graphic (115)
IDE (21)
Indy (5)
Internet / LAN (131)
IntraWeb (0)
Math (76)
Misc (127)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (268)
VCL (243)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

35 Visitors Online


 
...determine, if a Edit field has password characters?
Autor: Thomas Stutz
[ Print tip ]  

Tip Rating (7):  
     


// Determine, if a Edit Field has password characters
// Herausfinden, ob das Edit Feld Passwort Charakter hat
function HasPasswordChar(AHandle: HWND): Boolean;
var
  
dwStyle: DWORD;
begin
  
dwStyle := GetWindowLong(AHandle, GWL_STYLE);
  Result := (dwStyle and ES_PASSWORD) = ES_PASSWORD;
end;

// Set password characters for the Edit Field
// Passwort Charakter für ein Edit Feld setzen
procedure SetPasswordChar(AHandle: HWND; Value: Char);
var
  
S: String;
  len: Integer;
begin
  
len := Sendmessage(AHandle, WM_GETTEXTLENGTH, 0, 0);
  SetLength(S, len);
  SendMessage(AHandle, WM_GETTEXT, len+1, lparam(@S[1]));
  SendMessage(AHandle, EM_SETPASSWORDCHAR, Ord(Value), 0);
  SendMessage(AHandle, WM_SETTEXT, 0, Integer(PChar(S)));
end;

// Cancel the password characters and reveal the text
// Password Charakter aufheben und den Text anzeigen
procedure CancelPasswordChar(AHandle: HWND);
var
  
S: string;
  len: Integer;
begin
  
len := SendMessage(AHandle, WM_GETTEXTLENGTH, 0, 0);
  SetLength(S, len);
  SendMessage(AHandle, WM_GETTEXT, len + 1, lParam(@S[1]));
  SendMessage(AHandle, EM_SETPASSWORDCHAR, 0, 0);
  SendMessage(AHandle, WM_SETTEXT, 0, Integer(PChar(S)));
end;

// Example:
procedure TForm1.Button1Click(Sender: TObject);
var
  
wnd: HWND;
begin
  
wnd := FindWindowEx(GetForeGroundWindow, 0, 'TEdit', nil);
  if wnd <> 0 then
    
SetPasswordChar(wnd,'*');
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners