delphi 中 InputQuery 实现密码输入  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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消息的处理!

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.045051097869873 seconds