Delphi Inputbox,InputQuery用法

Delphi :InputQuery,InputBox用法及区别

function InputQuery(const ACaption, APrompt: string; var Value: string): Boolean;
InputQuery返回值为是否点了OK 输入的字符串放在了变量Value中

function InputBox(const ACaption, APrompt, ADefault: string): string;
inputBox返回值是字符串,也就是输入的字符串

procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
begin
//点击了OK按钮后,则
if InputQuery('标题','提示字符',s) then
begin
if s<>'' then //如果输入不为空则
   showmessage(s);
end;

 


end;

procedure TForm1.Button2Click(Sender: TObject);
var
s:string;
begin
s:=InputBox('标题','提示字符',s);
if s<>'' then
showmessage(s);
end;

Delphi通过自定义消息自定义Inputbox,使其支持掩码并修改按钮的caption

首先自定义一个消息ID

const
InputBoxMessage = WM_USER + 200;

接着声明并实现该消息的处理过程

procedure InputBoxSetPasswordChar(var Msg: TMessage); message InputBoxMessage;//声明

procedure Tfrm.InputBoxSetPasswordChar(var Msg: TMessage);//实现
var
hInputForm, hEdit, hButton: HWND;
begin
hInputForm := Screen.Forms[0].Handle;
if (hInputForm <> 0) then
begin
    hEdit := FindWindowEx(hInputForm, 0, 'TEdit', nil);
    SendMessage(hEdit, EM_SETPASSWORDCHAR, Ord('*'), 0);
      // Change button text:
    hButton := FindWindowEx(hInputForm, 0, 'TButton', 'Cancel');
    SendMessage(hButton, WM_SETTEXT,0, Integer(PChar('取消')));
    hButton := FindWindowEx(hInputForm, 0, 'TButton', 'OK');
    SendMessage(hButton, WM_SETTEXT,0, Integer(PChar('确定')));
end;
end;

 

使用自定义后的InputBox

PostMessage(Handle, InputBoxMessage, 0, 0);
InputBox('请设置解锁密码','请设置解锁密码(不能为空):','');

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值