forked from pozitronik/CloudMailRu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AskPassword.pas
78 lines (64 loc) · 2.06 KB
/
AskPassword.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
unit AskPassword;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, MRC_Helper;
type
TAskPasswordForm = class(TForm)
PasswordEditLabel: TLabel;
PasswordEdit: TEdit;
OkButton: TButton;
UseTCPwdMngrCB: TCheckBox;
class function AskPassword(ParentWindow: HWND; AccountName: WideString; var Password: WideString; var UseTCPwdMngr: Boolean): integer;
procedure PasswordEditChange(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
procedure WMHotKey(var Message: TMessage); message WM_HOTKEY;
public
{ Public declarations }
end;
var
AskPasswordForm: TAskPasswordForm;
implementation
{$R *.dfm}
{ TAskPasswordForm }
class function TAskPasswordForm.AskPassword(ParentWindow: HWND; AccountName: WideString; var Password: WideString; var UseTCPwdMngr: Boolean): integer;
var
AskPasswordForm: TAskPasswordForm;
begin
try
AskPasswordForm := TAskPasswordForm.Create(nil);
AskPasswordForm.ParentWindow := ParentWindow;
AskPasswordForm.Caption := AccountName + ' password';
RegisterHotKey(AskPasswordForm.Handle, 1, 0, VK_ESCAPE);
RegisterHotKey(AskPasswordForm.Handle, 2, 0, VK_RETURN);
result := AskPasswordForm.ShowModal;
if result = mrOk then
begin
Password := AskPasswordForm.PasswordEdit.Text;
UseTCPwdMngr := AskPasswordForm.UseTCPwdMngrCB.Checked;
end;
finally
FreeAndNil(AskPasswordForm);
end;
end;
procedure TAskPasswordForm.FormActivate(Sender: TObject);
begin
CenterWindow(Self.ParentWindow, Self.Handle);
end;
procedure TAskPasswordForm.FormShow(Sender: TObject);
begin
(Sender as TAskPasswordForm).PasswordEdit.SetFocus;
end;
procedure TAskPasswordForm.PasswordEditChange(Sender: TObject);
begin
OkButton.Enabled := PasswordEdit.Text <> '';
end;
procedure TAskPasswordForm.WMHotKey(var Message: TMessage);
begin
if Message.LParamHi = VK_ESCAPE then Close;
if (Message.LParamHi = VK_RETURN) and OkButton.Enabled then OkButton.Click;
end;
end.