怎么获取application.MessageBox()的返回值?分别有哪些返回值?

anytimer 2004-08-12 05:27:58
怎么获取application.MessageBox()的返回值?分别有哪些返回值?请问以下代码对吗?
if application.MessageBox('删除数据'¸'提示',65)=MB_OK then
begin
edit1.Text:='12';
end;
...全文
153 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
boatzm 2004-08-12
  • 打赏
  • 举报
回复
hoho
超详细的!
insert2003 2004-08-12
  • 打赏
  • 举报
回复
Delphi帮助
anytimer 2004-08-12
  • 打赏
  • 举报
回复
谢谢
kaguo 2004-08-12
  • 打赏
  • 举报
回复
类型如下
mbYes A button with 'Yes' on its face.
mbNo A button the text 'No' on its face.
mbOK A button the text 'OK' on its face.
mbCancel A button with the text 'Cancel' on its face.
mbAbort A button with the text 'Abort' on its face
mbRetry A button with the text 'Retry' on its face
mbIgnore A button the text 'Ignore' on its face
mbAll A button with the text 'All' on its face
mbNoToAll A button with the text 'No to All' on its face
mbYesToAll A button with the text 'Yes to All' on its face

mbHelp A button with the text 'Help' on its face
kaguo 2004-08-12
  • 打赏
  • 举报
回复
TMsgDlgButtons defines a set of values used by MessageDlg and MessageDlgPos.

Unit

Dialogs

type

TMsgDlgBtn = (mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore, mbAll, mbNoToAll, mbYesToAll, mbHelp);

TMsgDlgButtons = set of TMsgDlgBtn;
const

mbYesNoCancel = [mbYes, mbNo, mbCancel];

mbYesAllNoAllCancel = [mbYes, mbYesToAll, mbNo, mbNoToAll, mbCancel];

mbOKCancel = [mbOK, mbCancel];
mbAbortRetryIgnore = [mbAbort, mbRetry, mbIgnore];
mbAbortIgnore = [mbAbort, mbIgnore];

Description

The TMsgDlgButtons type defines the set of values a button in a message box can have. The TMsgDlgButtons type is used by the MessageDlg and MessageDlgPos functions. The following tables lists the possible values:

Value Meaning

mbYes A button with 'Yes' on its face.
mbNo A button the text 'No' on its face.
mbOK A button the text 'OK' on its face.
mbCancel A button with the text 'Cancel' on its face.
mbAbort A button with the text 'Abort' on its face
mbRetry A button with the text 'Retry' on its face
mbIgnore A button the text 'Ignore' on its face
mbAll A button with the text 'All' on its face
mbNoToAll A button with the text 'No to All' on its face
mbYesToAll A button with the text 'Yes to All' on its face

mbHelp A button with the text 'Help' on its face

In addition, the Dialogs unit defines the following constants for commonly used TMsgDlgButtons values:

Constant Meaning

mbYesNoCancel mbYes, mbNo, and mbCancel
mbYesNoAllCancel mbYes, mbYesToAll, mbNo, mbNoToAll, and mbCancel
mbOKCancel mbOK and mbCancel
mbAbortRetryIgnore mbAbort, mbRetry, and mbIgnore
mbAbortIgnore mbAbort, mbIgnore
应用程序在运行当中经常要输出各种即时信息,Delphi提供了多种形式的消息对话框可以满足这些要求,尽管可以使用各种标志定制一个消息框,但仍不能将自己的图标放在消息框内,也不能修改其标准行为去创建自己的消息框,其实通过调用函数MessageBoxIndirect()就很容易绕过这些明确的限制,这是一个功能很强、易于使用的函数。 ---- 此函数在WINDOWS单元里面,文件位于Delphi安装路径Source\Rtl\Win里面,需要指出的是,Delphi的原代码中它的返回值类型是BOOL型,而实质上它的返回值应为Integer。修改方法:在WINDOWS单元中找到此函数后,把BOOL改为Integer,共有三处要修改,然后在Delphi安装路径Lib中找到WINDOWS.DCU文件,把它改名或者删除,并把修改后的WINDOWS.PAS源码复制到Lib路径中。 ---- 该函数只有一个参数,类型是TMsgBoxParams,它的结构及说明如下: tagMSGBOXPARAMSA = packed record cbSize: UINT; {数据结构的长度} hwndOwner: HWND; {所有者窗口句柄} hInstance: HINST; {应用程序实例句柄} lpszText: PAnsiChar; {在消息框客户区内显示的文本} lpszCaption: PAnsiChar; {标题栏文本} dwStyle: DWORD; {确定消息框内按钮和图符 的数量及种类的MB_标志} lpszIcon: PAnsiChar; {从资源文件中取出的一个 图符资源的名字} dwContextHelpId: DWORD; {指定帮助文本的ID号} lpfnMsgBoxCallback: TPRMsgBoxCallback; {当用户按下HELP按钮时调用的一个回 调函数} dwLanguageId: DWORD; {显示在按钮内文本的语言定义} end; ---- 由于直接使用此函数比较复杂,我们可以自定义一个函数来封装此函数,对它进行简化,在用法上尽量做到与Delphi的消息框相一致,自定义函数代码如下: function MessageEx (lText,lCaption:PChar; lStyle:DWord;lIcon:PChar):Integer; var Msg:TMsgBoxParams; begin Msg.cbSize:=Sizeof(Msg); Msg.hwndOwner:=Application.Handle; Msg.hInstance:=hinstance; Msg.lpszText:=lText; Msg.lpszCaption:=lCaption; Msg.dwStyle:=lStyle; Msg.lpszIcon:=lIcon; Msg.dwContextHelpId:=1; Msg.lpfnMsgBoxCallback:=nil; Msg.dwLanguageId:=LANG_NEUTRAL; Result:=MessageBoxIndirect(Msg); end; ---- 要想在消息框中显示自己的图标,先准备一个装有图标的资源文件,加在程序中,如{$R c:\mydir\myres.res},在lStyle参数里除了所需的MB_标志外还要加上MB_USERICON标志,并在最后一个参数里写上资源文件中图标的名字,如果不想使用自定义的图标,可将最后一个参数设为nil。函数的其它用法和返回值的处理与Delphi提供的消息框一样。 ---- 强烈建议把自定义函数放在一个单元文件里,并把此文件放在Delphi的搜索路径如Lib下,以后只需要把此单元加在uses语句里,就可以直接使用自定义函数,非常方便。
应用程序在运行当中经常要输出各种即时信息,Delphi提供了多种形式的消息对话框可以满足这些要求,尽管可以使用各种标志定制一个消息框,但仍不能将自己的图标放在消息框内,也不能修改其标准行为去创建自己的消息框,其实通过调用函数MessageBoxIndirect()就很容易绕过这些明确的限制,这是一个功能很强、易于使用的函数。 ---- 此函数在WINDOWS单元里面,文件位于Delphi安装路径Source\Rtl\Win里面,需要指出的是,Delphi的原代码中它的返回值类型是BOOL型,而实质上它的返回值应为Integer。修改方法:在WINDOWS单元中找到此函数后,把BOOL改为Integer,共有三处要修改,然后在Delphi安装路径Lib中找到WINDOWS.DCU文件,把它改名或者删除,并把修改后的WINDOWS.PAS源码复制到Lib路径中。 ---- 该函数只有一个参数,类型是TMsgBoxParams,它的结构及说明如下: tagMSGBOXPARAMSA = packed record cbSize: UINT; {数据结构的长度} hwndOwner: HWND; {所有者窗口句柄} hInstance: HINST; {应用程序实例句柄} lpszText: PAnsiChar; {在消息框客户区内显示的文本} lpszCaption: PAnsiChar; {标题栏文本} dwStyle: DWORD; {确定消息框内按钮和图符 的数量及种类的MB_标志} lpszIcon: PAnsiChar; {从资源文件中取出的一个 图符资源的名字} dwContextHelpId: DWORD; {指定帮助文本的ID号} lpfnMsgBoxCallback: TPRMsgBoxCallback; {当用户按下HELP按钮时调用的一个回 调函数} dwLanguageId: DWORD; {显示在按钮内文本的语言定义} end; ---- 由于直接使用此函数比较复杂,我们可以自定义一个函数来封装此函数,对它进行简化,在用法上尽量做到与Delphi的消息框相一致,自定义函数代码如下: function MessageEx (lText,lCaption:PChar; lStyle:DWord;lIcon:PChar):Integer; var Msg:TMsgBoxParams; begin Msg.cbSize:=Sizeof(Msg); Msg.hwndOwner:=Application.Handle; Msg.hInstance:=hinstance; Msg.lpszText:=lText; Msg.lpszCaption:=lCaption; Msg.dwStyle:=lStyle; Msg.lpszIcon:=lIcon; Msg.dwContextHelpId:=1; Msg.lpfnMsgBoxCallback:=nil; Msg.dwLanguageId:=LANG_NEUTRAL; Result:=MessageBoxIndirect(Msg); end; ---- 要想在消息框中显示自己的图标,先准备一个装有图标的资源文件,加在程序中,如{$R c:\mydir\myres.res},在lStyle参数里除了所需的MB_标志外还要加上MB_USERICON标志,并在最后一个参数里写上资源文件中图标的名字,如果不想使用自定义的图标,可将最后一个参数设为nil。函数的其它用法和返回值的处理与Delphi提供的消息框一样。 ---- 强烈建议把自定义函数放在一个单元文件里,并把此文件放在Delphi的搜索路径如Lib下,以后只需要把此单元加在uses语句里,就可以直接使用自定义函数,非常方便。

5,402

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧