Delphi InputBox进行密码输入?

前端之家收集整理的这篇文章主要介绍了Delphi InputBox进行密码输入?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
输入框:
  1. answer:=InputBox('a','b','c');

工作很好,但是我正在寻找一个蒙版的人,就像一个密码框,你只看到小星星,而不是打字符.

解决方法

您可以将Windows消息发送到由InputBox创建的编辑控件,该控件将标记用于输入密码的编辑控件.代码如下从 http://www.swissdelphicenter.ch/en/showcode.php?id=1208
  1. const
  2. InputBoxMessage = WM_USER + 200;
  3.  
  4. type
  5. TForm1 = class(TForm)
  6. Button1: TButton;
  7. procedure Button1Click(Sender: TObject);
  8. private
  9. procedure InputBoxSetPasswordChar(var Msg: TMessage); message InputBoxMessage;
  10. public
  11. end;
  12.  
  13. var
  14. Form1: TForm1;
  15.  
  16. implementation
  17.  
  18. {$R *.DFM}
  19.  
  20. procedure TForm1.InputBoxSetPasswordChar(var Msg: TMessage);
  21. var
  22. hInputForm,hEdit,hButton: HWND;
  23. begin
  24. hInputForm := Screen.Forms[0].Handle;
  25. if (hInputForm <> 0) then
  26. begin
  27. hEdit := FindWindowEx(hInputForm,'TEdit',nil);
  28. {
  29. // Change button text:
  30. hButton := FindWindowEx(hInputForm,'TButton',nil);
  31. SendMessage(hButton,WM_SETTEXT,Integer(PChar('Cancel')));
  32. }
  33. SendMessage(hEdit,EM_SETPASSWORDCHAR,Ord('*'),0);
  34. end;
  35. end;
  36.  
  37. procedure TForm1.Button1Click(Sender: TObject);
  38. var
  39. InputString: string;
  40. begin
  41. PostMessage(Handle,InputBoxMessage,0);
  42. InputString := InputBox('Input Box','Please Enter a Password','');
  43. end;

猜你在找的Delphi相关文章