Delphi 中 InputQuery 实现密码输入


本文整理自网络,侵删。

 
修改用户口令时为了避免自己建立新的口令修改窗口,借用delphi中的标准输入对话框。
实现代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
InputBoxMessage = WM_USER + 200;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure InputBoxSetPasswordChar(var Msg: TMessage); message InputBoxMessage;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
InputString: string;
begin
PostMessage(Handle, InputBoxMessage, 0, 0);
if InputQuery('Input Box', 'Please Enter a Password', InputString ) then
ShowMessage(InputString);
end;
procedure TForm1.InputBoxSetPasswordChar(var Msg: TMessage);
var
hInputForm, hEdit: HWND;
begin
hInputForm := Screen.Forms[0].Handle;
if (hInputForm <> 0) then
begin
hEdit := FindWindowEx(hInputForm, 0, 'TEdit', nil);
SendMessage(hEdit, EM_SETPASSWORDCHAR, Ord('*'), 0);
end;
end;
end.
这种方法实现的比较巧妙!重点是PostMessage(Handle, InputBoxMessage, 0, 0);
和对InputBoxMessage消息的处理!

相关阅读 >>

图解qq群如何快速找到自己想要的Delphi资源

Delphi selectdirectory 选择文件夹

Delphi playsound(); 停止播放

Delphi 调用外部程序获取程序id,并能关闭该程序

Delphi getfilesize 获取文件大小 2

Delphi三层开发小技巧:tclientdataset的delta妙用

Delphi 动态创建窗体

Delphi 关于虚拟的desktop的编程

Delphi ado 连接 excel (附excel各个版本的版本号)

Delphi 新版 thttpclient组件同步下载文件方法

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...