Czy można maskować przy pomocy * tekst wprowadzany w polu edycji InputBox, tak jak do haseł ?
0
2
Standardowo nie, ale istnieje hack, który pozwoli zamaskować wartość w polu edycyjnym tego okna. W razie czego, stworzenie podobnego okienka i napisanie podobnej funkcji do InputBox to kilka linijek kodu.
2
Można też się pobawić:
const
WM_INPUTBOXSETTYPEPASS = WM_USER + 1000;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure InputBoxSetTypePass(var Msg: TMessage); message WM_INPUTBOXSETTYPEPASS;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.InputBoxSetTypePass(var Msg: TMessage);
var
hInputForm, hInputEdit, hButtonCancel: HWND;
edInput: TEdit;
begin
hInputForm:= Screen.Forms[0].Handle;
if (hInputForm <> 0) then
begin
hInputEdit:= FindWindowEx(hInputForm, 0, 'TEdit', nil);
if hInputEdit <> INVALID_HANDLE_VALUE then
begin
edInput:= TEdit(FindControl(hInputEdit));
if Assigned(edInput) then
begin
edInput.Font.Charset:= 2; //SYMBOL_CHARSET
edInput.PasswordChar:= 'l'; //ascii = 108
end;
end;
//ewentualnie można zwyczjne * wtedy wystarczy
//SendMessage(hInputEdit, EM_SETPASSWORDCHAR, Ord('*'), 0);
//zmiana tekstu przycisku Cancel
hButtonCancel:= FindWindowEx(hInputForm, 0, 'TButton', 'Cancel');
if hInputEdit <> INVALID_HANDLE_VALUE then
SendMessage(hButtonCancel, WM_SETTEXT, 0, Integer(PChar('Anuluj')));
end
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Password: string;
begin
PostMessage(Handle, WM_INPUTBOXSETTYPEPASS, 0, 0);
Password:= InputBox('Wpisz hasło', 'Proszę podać hasło: ', '');
ShowMessage(Password);
end;