delphi的消息对话框.docx_第1页
delphi的消息对话框.docx_第2页
delphi的消息对话框.docx_第3页
delphi的消息对话框.docx_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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);varstr : string;beginstr:=inputbox(南山古桃的对话框,请输入要平方的数据,0);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 MeaningMB_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 MeaningMB_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 MeaningMB_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 ValuesThe 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 MeaningIDABORT 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 thenbegin /如果按下“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。大家可以参照上面的代码略作修改来体会一

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论