【转】Delphi的消息对话框
Delphi的消息对话框
输入输出inputBox()函数MessageBox()ShowMessage
对话框是Windows操作系统中程序与用户沟通的一种常见的交互方式,对话框可以向用户提供当前程序的运行状况,也可以接受用户输入的信息,在 Delphi中,对话框函数大体上可以分为两种——输入对话框函数和输出对话框函数。
输入对话框函数用于接收用户在程序运行过程中输入的信息,其中包括 InputBox(),InputQuery()函数。
输出对话框函数则用于显示一个对话框窗体和向用户报告当前程序的运行状态等信息,它包括ShowMessage()函数、 MessageDlg()函数。
下面就对各个函数分别加以介绍。
输入:
InputBox()函数
对话框函数中的InputBox()函数用于在程序运行的过程中显示一个包含一个字符串和按钮信息的输入对话框。
它的语法结构如下所示:
function InputBox(const ACaption, APrompt, ADefault: string): string;
下面以一个示例来说明InputBox()函数的用法:
procedure TForm1.Button1Click(Sender: TObject);
var
str : string;
begin
str:=inputbox(');
edit1.Text:='南山古桃 得到的平方是:' + floattostr(strtofloat(str)*strtofloat(str));
end;
输出:
1.ShowMessage()函数--最常用,最简单
对话框函数中的ShowMessage()函数用于在程序运行的过程中显示包含一个字符串信息的对话框。
它的语法结构如下所示:
ShowMessage(const Msg:string);
如:ShowMessage('南山古桃 问候您!');
2.MessageBox()函数--正式程序时常用此函数输出(个人观点)
例:
--Application.MessageBox('MessageBox','警告',MB_ICONWARNING+MB_YesNo);
--MessageBox(Form1.Handle,'MessageBox','提示',MB_ICONINFORMATION+MB_OkCancel);
--MessageBox(Form1.Handle,'MessageBox','提示‘,MB_ICONINFORMATION+MB_OkCancel+MB_DEFBUTTON2);
-- if MessageBox(Form1.Handle,'MessageBox','提示',MB_ICONINFORMATION+MB_OkCancel)= idOk then
begin
ShowMessage('Ok');
end;
//********************************************************************************************************************
在Delphi中输入MessageBox按下F1,会出来帮助,可以查阅具体参数
int MessageBox(
HWND hWnd, // handle of owner window
LPCTSTR lpText, // address of text in
message box
LPCTSTR lpCaption, // address of title of
message box
UINT uType // style of message box
);
Specifies a set of bit flags that determine the contents and behavior of the
dialog box. This parameter can be a combination of flags from the following
groups of flags.
Specify one of the following flags to indicate the buttons contained in the
message box:
Flag Meaning
MB_ABORTRETRYIGNORE The message box contains three push
buttons: Abort, Retry, and Ignore.
MB_OK The message box contains one push button: OK. This is
the default.
MB_OKCANCEL The message box contains two push buttons: OK and
Cancel.
MB_RETRYCANCEL The message box contains two push buttons:
Retry and Cancel.
MB_YESNO The message box contains two push buttons: Yes and
No.
MB_YESNOCANCEL The message box contains three push buttons:
Yes, No, and Cancel.
Specify one of the following flags to display an icon in the message box:
Flag Meaning
MB_ICONEXCLAMATION,
MB_ICONWARNING
An exclamation-point icon appears in the message box.
MB_ICONINFORMATION, MB_ICONASTERISK
An icon consisting of a lowercase letter i in a circle
appears in the message box.
MB_ICONQUESTION A question-mark icon appears in the message
box.
MB_ICONSTOP,
MB_ICONERROR,
MB_ICONHAND
A stop-sign icon appears in the message box.
Specify one of the following flags to indicate the default button:
Flag Meaning
MB_DEFBUTTON1 The first button is the default button.
MB_DEFBUTTON1 is the default unless MB_DEFBUTTON2, MB_DEFBUTTON3, or
MB_DEFBUTTON4 is specified.
MB_DEFBUTTON2 The second button is the default button.
MB_DEFBUTTON3 The third button is the default button.
MB_DEFBUTTON4 The fourth button is the default button.
Return Values
The return value is zero if there is not enough memory to create the message
box.
If the function succeeds, the return value is one of the following menu-item
values returned by the dialog box:
Value Meaning
IDABORT Abort button was selected.
IDCANCEL Cancel button was selected.
IDIGNORE Ignore button was selected.
IDNO No button was selected.
IDOK OK button was selected.
IDRETRY Retry button was selected.
IDYES Yes button was selected.
If a message box has a Cancel button, the function returns the IDCANCEL value
if either the ESC key is pressed or the Cancel button is selected. If the
message box has no Cancel button, pressing ESC has no effect.
//********************************************************************************************************************
3.MessageDlg()函数--南山古桃 不知道为什么出不来中文?
对话框函数中的MessageDlg()函数用于在程序运行的过程中显示包含一个字符串、位图和按钮信息的对话框。
它的语法结构如下所示:
function MessageDlg(const Msg: string; AType: TMsgDlgType; AButtons:
TMsgDlgButtons; HelpCtx: Longint): Word;
下面以一个示例来说明MessageDlg()函数的用法:
procedure TForm1.Button3Click(Sender: TObject);
begin
//显示一个问号和Yes、No两个按钮的输出对话框
if MessageDlg('你想退出本程序吗?',
mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
//如果按下“yes”就显示一个感叹号的输出对话框
MessageDlg('按下OK就退出', mtInformation,
[mbOk], 0);
Close;
end;
end;
在本例中MessageDlg()函数中使用到的参数Atype是TmsgDlgType类型,它的值主要有以下几种:mtWarning、 mtError、mtInformation、mtConfirmation,、mtCustom;而参数Abuttons是 TmsgDlgButtons类型,它的值主要有以下几种:mbYes、mbNo、 mbOK,、mbCancel、mbAbort、mbRetry、mbIgnore、mbAll、mbHelp。大家可以参照上面的代码略作修改来体会一下。
messagebox(handle,pchar('无效的产品信息'+#13#10+'请不要更改注册信息'),pchar('错误'),mb_ok+mb_iconerror+mb_applmodal);
4.MessageDlgPos
MessageDlgPos('控制位置100,200',mtWarning,[mbYes,mbNO],0,
100, 200);
MessageDlgPos('控制位置 屏幕中央',mtWarning,[mbYes,mbNO],0, -1,
-1);
【转】Delphi的消息对话框的更多相关文章
- delphi的消息对话框
delphi的消息对话框,类似VFP中的WAIT和MESSAGEBOXdelphi的消息对话框,类似VFP中的WAIT和MESSAGEBOX1.最简单的是:showmessage() 它只有一个OK按 ...
- Delphi——Window 消息 - 转载▼
Delphi是Borland公司的一种面向对象的可视化软件开发工具. Delphi集中了Visual C++和Visual Basic两者的优点:容易上手.功能强大,特别是在界面设计.数据库编程.网络 ...
- Qt——消息对话框的设计
1.消息对话框是什么 消息对话框(MessageBox)提供了一个模态对话框,用来通知用户某些信息,或者用来询问用户一个问题并获得一个答复. 先看下面2张图—— 第一张图是网易云音乐的界面截图,在删除 ...
- JavaScript入门篇 第二天(消息对话框+网页弹出)
提问(prompt 消息对话框) prompt弹出消息对话框,通常用于询问一些需要与用户交互的信息.弹出消息对话框(包含一个确定按钮.取消按钮与一个文本输入框). 语法: prompt(str1, s ...
- MFC编程入门之十六(对话框:消息对话框)
前面几节讲了属性页对话框,我们可以根据所讲内容方便的建立自己的属性页对话框.本节讲解Windows系统中最常用最简单的一类对话框--消息对话框. 我们在使用Windows系统的过程中经常会见到消息对话 ...
- [转载]ExtJs4 笔记(6) Ext.MessageBox 消息对话框
作者:李盼(Lipan) 出处:[Lipan] (http://www.cnblogs.com/lipan/)版权声明:本文的版权归作者与博客园共有.转载时须注明本文的详细链接,否则作者将保留追究其法 ...
- 弹出消息对话框ScriptManager
//直接调用WebMessageBox方法 #region 弹出消息对话框 /// <summary> /// 弹出消息对话框 /// </summary> /// <p ...
- Delphi TFindDialog TReplaceDialog对话框在Memo中的使用
Delphi TFindDialog TReplaceDialog对话框的使用 下载地址1: http://download.csdn.net/detail/teststudio/6408383 ...
- 确认(confirm 消息对话框)
confirm 消息对话框通常用于允许用户做选择的动作(包括一个确定按钮和一个取消按钮). 语法: confirm(str) str:在消息对话框中要显示的文本 返回值: 当用户点击"确定& ...
随机推荐
- SQLSERVER的兼容级别
今天采用SQL Mannager 2008连接远程的sqlserver数据库,之后弹出一个对话框,修改SQL兼容级别,当时每太注意,一下点击了确定按钮,结果导致两个系统SQL只想全部出错,幸亏发现的早 ...
- 菜鸟-手把手教你把Acegi应用到实际项目中(11)-切换用户
在某些应用场合中,我们可能需要用到切换用户的功能,从而以另一用户的身份进行相关操作.这一点类似于在Linux系统中,用su命令切换到另一用户进行相关操作. 既然实际应用中有这种场合,那么我们 ...
- [VB.NET]拖动操作的技术基础
1.设置需要接受拖动事件的控件的AllowDrop属性为True,在开发界面时配置,不可通过代码配置 2.在DragEnter事件处理程序里,为e.Effet设置枚举值,否则拖动无效 Private ...
- Map集合的遍历方式:
迭代器来遍历 : entrySet() ; keySet(); values(); eg.HashMap<String,String> map = new HashMap<Strin ...
- Flex 播放视频
Flex提供视频控件(VideoDisplay Control)播放图像和声音. 视频控件只支持播放,暂停和停止功能.不提供倒退和前进功能.只支持播放FLV格式的影片. 1. 视频控件标签 对应的MX ...
- 8051学习笔记——IIC与EEPROM实验
main.c #include <reg51.h> #include "iic.h" #define AT24C02 0xa0 //AT24C02 地址 sbit LS ...
- LED点阵显示名字
学习了一周的单片机,然后中途有事打断了两周,现在温习一下之前学的东西,用“普中科技单片机”上的LED点阵显示自己的名字. P1接J19(绿).P2接J20(红),P0接J12(数码管段选):5V电压: ...
- SVN与TortoiseSVN实战:从入门到精通
SVN,版本控制程序,是支撑项目开发的基础工具. 在团队开发中,不管是程序员还是美工.测试等人员,都会用到SVN,通常会把SVN视为源代码管理工具,但对于SVN更准确的理解是: “帮助参与项目人员的管 ...
- centreon 降低rrd磁盘读写
参考 https://documentation.centreon.com/docs/centreon/en/2.7.x/faq/performance.html 修改rrdcached配置 vim ...
- npm命令大全
参考网站:https://docs.npmjs.com/ 有了npm,可以很快的找到特定服务要使用的包,进行下载.安装以及管理已经安装的包. npm 常用命令 npm install <name ...