本文整理自网络,侵删。
修改用户口令时为了避免自己建立新的口令修改窗口,借用delphi中的标准输入对话框。实现代码如下:unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;constInputBoxMessage = WM_USER + 200;typeTForm1 = class(TForm)Edit1: TEdit;Button1: TButton;procedure Button1Click(Sender: TObject);private{ Private declarations }procedure InputBoxSetPasswordChar(var Msg: TMessage); message InputBoxMessage;public{ Public declarations }end;varForm1: TForm1;implementation{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);varInputString: string;beginPostMessage(Handle, InputBoxMessage, 0, 0);if InputQuery('Input Box', 'Please Enter a Password', InputString ) thenShowMessage(InputString);end;procedure TForm1.InputBoxSetPasswordChar(var Msg: TMessage);varhInputForm, hEdit: HWND;beginhInputForm := Screen.Forms[0].Handle;if (hInputForm <> 0) thenbeginhEdit := FindWindowEx(hInputForm, 0, 'TEdit', nil);SendMessage(hEdit, EM_SETPASSWORDCHAR, Ord('*'), 0);end;end;end.这种方法实现的比较巧妙!重点是PostMessage(Handle, InputBoxMessage, 0, 0);和对InputBoxMessage消息的处理!
相关阅读 >>
更多相关阅读请进入《Delphi》频道 >>