messagebox函数

更新时间:2023-03-01 08:12:34 阅读: 评论:0

MessageBox函数

MessageBox 函数用于创建、显示并操作一个消息对话框。该对话框包含由调用程序定义的信息和标题,以及预先定义的图标和按钮。
定义(适用于Visual Basic 6.0):Declare Function MessageBox Lib "ur32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
参数说明:

hWnd:
指定该对话框的所有者窗口。如果该参数为空(0),则该对话框不属于任何窗口(?)。
lpText:
显示在对话框中的消息。
lpCaption:
在对话框标题栏中显示的字符串表达式。如果该参数为空(vbNullString),则使用默认的“错误”作为对话框的标题。
wType:
指定显示按钮的数目及形式,使用的图标样式,缺省按钮是什么以及消息框的强制回应等。可以为下列常数之一或某几个数值相加的和。
指定按钮样式:
MB_ABORTRETRYIGNORE
显示 Abort、Retry 及 Ignore 按钮。
MB_OK
只显示 OK 按钮。(默认)
MB_OKCANCEL
显示 OK 及 Cancel 按钮。
MB_RETRYCANCEL
显示 Retry 及 Cancel 按钮。
MB_YESNO
显示 Yes 及 No 按钮。
MB_YESNOCANCEL
显示 Yes、No 及 Cancel 按钮。
指定图标样式:
MB_ICONEXCLAMATION, MB_ICONWARNING
显示 Warning Message 图标。
MB_ICONINFORMATION, MB_ICONASTERISK
显示 Information Message 图标。
MB_ICONQUESTION
显示 Warning Query 图标。
MB_ICONSTOP, MB_ICONERROR, MB_ICONHAND
显示 Critical Message 图标。
指定默认按钮:
MB_DEFBUTTON1
第一个按钮是缺省值。(默认)
MB_DEFBUTTON2
第二个按钮是缺省值。
MB_DEFBUTTON3
第三个按钮是缺省值。
MB_DEFBUTTON4
第四个按钮是缺省值。
指定对话框模式等:
MB_APPLMODAL
应用程序强制返回;应用程序一直被挂起,直到用户对消息框作出响应才继续工作。
MB_SYSTEMMODAL
系统强制返回;全部应用程序都被挂起,直到用户对消息框作出响应才继续工作。
MB_TASKMODAL
MB_DEFAULT_DESKTOP_ONLY
MB_HELP
将Help按钮添加到消息框。
MB_RIGHT
文本为右对齐。
MB_RTLREADING
指定文本应为在希伯来和阿拉伯语系统中的从右到左显示。
MB_SETFOREGROUND
指定消息框窗口作为前景窗口。
MB_TOPMOST
MB_SERVICE_NOTIFICATION
MB_SERVICE_NOTIFICATION_NT3X
MB_SERVICE_NOTIFICATION
返回值:
如果没有足够内存创建消息对话框,则返回0。
如果函数成功运行,则返回下列数值之一:
IDABORT
用户点击了 Abort 按钮。
IDCANCEL
用户点击了 Cancel 按钮。
IDIGNORE
用户点击了 Ignore 按钮。
IDNO
用户点击了 No 按钮。
IDOK
用户点击了 OK 按钮。
IDRETRY
用户点击了 Retry 按钮。
IDYES
用户点击了 Yes 按钮。
如果对话框显示 Cancel 按钮,则按下 ESC 键与单击 Cancel 按钮的效果相同。
程序示例:

#include<windows.h>
//切记!当调用<windows.h>时,不要调用MFC!(Afx.h)
int main()
{
int result = MessageBox( NULL , TEXT("这是对话框") , TEXT("你好") , MB_ICONINFORMATION|MB_YESNO);
switch(result)/*注意!使用Unicode应用TEXT包围字串*/
{
ca IDYES:MessageBox(NULL,TEXT("您选择了YES"),TEXT("YES"),MB_OK);break;
ca IDNO:MessageBox(NULL,TEXT("您选择了NO"),TEXT("NO"),MB_OK);break;
}
return 0;
}

MessageBox函数的原文

The MessageBox function creates, displays, and operates a message box. The message box contains an application-defined message and title, plus any combination of predefined icons and push buttons.
Declaration:
Declare Function MessageBox Lib ur32 Alias MessageBoxA (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Parameters:
?hWnd
Identifies the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window.
?lpText
Points to a null-terminated string containing the message to be displayed.
?lpCaption
Points to a null-terminated string ud for the dialog box title. If this parameter is NULL, the default title Error is ud.
?uType
Specifies a t 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:
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:
MB_ICONEXCLAMATION,
MB_ICONWARNING
An exclamation-point icon appears in the message box.
MB_ICONINFORMATION, MB_ICONASTERISK
An icon consisting of a lowerca 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:
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 cond button is the default button.
MB_DEFBUTTON3
The third button is the default button.
MB_DEFBUTTON4
The fourth button is the default button.
Specify one of the following flags to indicate the modality of the dialog box:
MB_APPLMODAL
The ur must respond to the message box before continuing work in the window identified by the hWnd parameter. However, the ur can move to the windows of other applications and work in tho windows.
Depending on the hierarchy of windows in the application, the ur may be able to move to other windows within the application. All child windows of the parent of the message box are automatically disabled, but popup windows are not.
MB_APPLMODAL is the default if neither MB_SYSTEMMODAL nor MB_TASKMODAL is specified.
MB_SYSTEMMODAL
Same as MB_APPLMODAL except that the message box has the WS_EX_TOPMOST style. U system-modal message boxes to notify the ur of rious, potentially damaging errors that require immediate attention (for example, running out of memory). This flag has no effect on the ur's ability to interact with windows other than tho associated with hWnd.
MB_TASKMODAL
Same as MB_APPLMODAL except that all the top-level windows belonging to the current task are disabled if the hWnd parameter is NULL. U this flag when the calling application or library does not have a window handle available but still needs to prevent input to other windows in the current application without suspending other applications.
In addition, you can specify the following flags:
MB_DEFAULT_DESKTOP_ONLY
The desktop currently receiving input must be a default desktop; otherwi, the function fails. A default desktop is one an application runs on after the ur has logged on.
MB_HELP
Adds a Help button to the message box. Choosing the Help button or pressing F1 generates a Help event.
MB_RIGHT
The text is right-justified.
MB_RTLREADING
Displays message and caption text using right-to-left reading order on Hebrew and Arabic systems.
MB_SETFOREGROUND
The message box becomes the foreground window. Internally, Windows calls the SetForegroundWindow function for the message box.
MB_TOPMOST
The message box is created with the WS_EX_TOPMOST window style.
MB_SERVICE_NOTIFICATION
Windows NT only: The caller is a rvice notifying the ur of an event. The function displays a message box on the current active desktop, even if there is no ur logged on to the computer.
If this flag is t, the hWnd parameter must be NULL. This is so the message box can appear on a desktop other than the desktop corresponding to the hWnd.
For Windows NT version 4.0, the value of MB_SERVICE_NOTIFICATION has changed. See WINUSER.H for the old and new values. Windows NT 4.0 provides backward compatibility for pre-existing rvices by mapping the old value to the new value in the implementation of MessageBox and MessageBoxEx. This mapping is only done for executables that have a version number, as t by the linker, less than 4.0.
To build a rvice that us MB_SERVICE_NOTIFICATION, and can run on both Windows NT 3.x and Windows NT 4.0, you have two choices. 1. At link-time, specify a version number less than 4.0; or
2. At link-time, specify version 4.0. At run-time, u the GetVersionEx function to check the system version. Then when running on Windows NT 3.x, u MB_SERVICE_NOTIFICATION_NT3X; and on Windows NT 4.0, u MB_SERVICE_NOTIFICATION.
MB_SERVICE_NOTIFICATION_NT3X
Windows NT only: This value corresponds to the value defined for MB_SERVICE_NOTIFICATION for Windows NT version 3.51.
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:
IDABORT
Abort button was lected.
IDCANCEL
Cancel button was lected.
IDIGNORE
Ignore button was lected.
IDNO
No button was lected.
IDOK
OK button was lected.
IDRETRY
Retry button was lected.
IDYES
Yes button was lected.
If a message box has a Cancel button, the function returns the IDCANCEL value if either the ESC key is presd or the Cancel button is lected. If the message box has no Cancel button, pressing ESC has no effect.
程序示例:
#include <windows.h>
#include <stdio.h>
int main ( int argc , char *argv[] )
{
//调用API函数MessageBox
int nSelect=::MessageBox(NULL,正文:Hello World,标题:MessageBox程序示例,MB_OKCANCEL | MB_ICONINFORMATION | MB_DEFBUTTON1 );
//API函数前加“::”符号,表示这是一个全局的函数,以与c++类的成员函数相区分
if( IDOK == nSelect )
{
printf(您按了“确定” );
}
el
{
printf(您按了“取消” );
}
return 0;
}


请问:VB 里面的MessageBox要怎么用,整个函数是什么样的?

MessageBox是.Net的类 你说的是Msgbox? MsgBox 函数 在对话框中显示消息,等待用户单击按钮,并返回一个 Integer 告诉用户单击哪一个按钮。 语法 MsgBox(prompt[, buttons] [, title] [, helpfile, context]) MsgBox 函数的语法具有以下几个命名参数: 部分 描述 Prompt 必需的。字符串表达式,作为显示在对话框中的消息。prompt 的最大长度大约为 1024 个字符,由所用字符的宽度决定。如果 prompt 的内容超过一行,则可以在每一行之间用回车符 (Chr(13))、换行符 (Chr(10)) 或是回车与换行符的组合 (Chr(13) & Chr(10)) 将各行分隔开来。 Buttons 可选的。数值表达式是值的总和,指定显示按钮的数目及形式,使用的图标样式,缺省按钮是什么以及消息框的强制回应等。如果省略,则 buttons 的缺省值为 0。 Title 可选的。在对话框标题栏中显示的字符串表达式。如果省略 title,则将应用程序名放在标题栏中。 Helpfile 可选的。字符串表达式,识别用来向对话框提供上下文相关帮助的帮助文件。如果提供了 helpfile,则也必须提供 context。 Context 可选的。数值表达式,由帮助文件的作者指定给适当的帮助主题的帮助上下文编号。如果提供了 context,则也必须提供 helpfile。 设置值 buttons 参数有下列设置值: 常数 值 描述 vbOKOnly 0 只显示 OK 按钮。 VbOKCancel 1 显示 OK 及 Cancel 按钮。 VbAbortRetryIgnore 2 显示 Abort、Retry 及 Ignore 按钮。 VbYesNoCancel 3 显示 Yes、No 及 Cancel 按钮。 VbYesNo 4 显示 Yes 及 No 按钮。 VbRetryCancel 5 显示 Retry 及 Cancel 按钮。 VbCritical 16 显示 Critical Message 图标。 VbQuestion 32 显示 Warning Query 图标。 VbExclamation 48 显示 Warning Message 图标。 VbInformation 64 显示 Information Message 图标。 vbDefaultButton1 0 第一个按钮是缺省值。 vbDefaultButton2 256 第二个按钮是缺省值。 vbDefaultButton3 512 第三个按钮是缺省值。 vbDefaultButton4 768 第四个按钮是缺省值。 vbApplicationModal 0 应用程序强制返回;应用程序一直被挂起,直到用户对消息框作出响应才继续工作。 vbSystemModal 4096 系统强制返回;全部应用程序都被挂起,直到用户对消息框作出响应才继续工作。 vbMsgBoxHelpButton 16384 将Help按钮添加到消息框 VbMsgBoxSetForeground 65536 指定消息框窗口作为前景窗口 vbMsgBoxRight 524288 文本为右对齐 vbMsgBoxRtlReading 1048576 指定文本应为在希伯来和阿拉伯语系统中的从右到左显示 第一组值 (0–5) 描述了对话框中显示的按钮的类型与数目;第二组值 (16, 32, 48, 64) 描述了图标的样式;第三组值 (0, 256, 512) 说明哪一个按钮是缺省值;而第四组值 (0, 4096) 则决定消息框的强制返回性。将这些数字相加以生成 buttons 参数值的时候,只能由每组值取用一个数字。 注意 这些常数都是 Visual Basic for Applications (VBA) 指定的。结果,可以在程序代码中到处使用这些常数名称,而不必使用实际数值。 返回值 常数 值 描述 vbOK 1 OK vbCancel 2 Cancel vbAbort 3 Abort vbRetry 4 Retry

messagebox是c语言中的函数吗 如何用

准确来说是系统API函数原型是int MessageBox(HWND hWnd,LPCTSTR lpText,LPCTSTR lpCaption,UINT UType);比如写成#include <Windows.h>int main(){
MessageBox(0, "我是内容", "我是标题", MB_OK);
return 0;
}
运行截图就是

C语言中messagebox的用法

消息框的函数原型:
int MessageBox(HWND hwnd,LPCTSTR lpsztext,LPCSTR lpsztitle,UINT ustyle);

消息框函数有4个参数:
第1个参数是父窗口的句柄。为NULL,说明消息框没有父窗口。
第2个参数就是一个指向要显示字符串的指针
第3个参数是消息框本身的标题。
第4个参数是指定消息框的内容和形为(即该消息框有几个按钮、文本对齐等状态,可以在20多个属性值中进行组合)

MessageBox的第4个参数可以是在WINUSER.H中定义的一组前缀以MB_开始的常数组合.
可以使用C语言的"或"(|)运算符将下面显示的三组中各选一个常数组合起来指定消息框的内容和形为:

显示哪些按钮:
#define MB_OK 0X00000000L
#define MB_OKCANCEL 0X00000001L
#define MB_ABORTRERYGNORE 0X00000002L
#define MB_YESNOCANCEL 0X00000003L
#define MB_YESNO 0X00000004L
#define RERYCANCEL 0X00000005L

焦点在哪个按钮上:
#define MB_DEFBUTTON1 0X00000000L
#define MB_DEFBUTTON2 0X00000100L
#define MB_DEFBUTTON3 0X00000200L
#define MB_DEFBUTTON4 0X00000300L

图示的外观:
#define MB_ICONHAND 0x00000010L
#define MB_ICONQUESTION 0x00000020L
#define MB_ICONEXCLAMATION 0x00000030L
#define MB_ICONASTERISK 0x00000040L

图示的某些有替代名称:
#define MB_ICONWARNING MB_ICONEXCLAMATION
#define MB_ICONERROR MB_ICONHAND
#define MB_ICONINFORMATION MB_ICONASTERISK
#define MB_ICONSTOP MB_ICONHAND

示例:
MessageBox(NULL, "Hello, Windows!","hello", MB_OK );
MessageBox(NULL, "Hello, Windows!","HelloMsg", MB_YESNO|MB_ICONEXCLAMATION) ;
MessageBox(NULL, "Hello, Windows!","HelloMsg", MB_YESNO|MB_DEFBUTTON1) ;//表示窗口出来后焦点 focus落在Yes(第一个)按钮上

VC++关于messagebox函数的问题

MB_ABORTRETRYIGNORE:消息框含有三个按钮:Abort,Retry和Ignore。

MB_OK:消息框含有一个按钮:OK。这是缺省值。

MB_OKCANCEL:消息框含有两个按钮:OK和Cancel。

MB_RETRYCANCEL:消息框含有两个按钮:Retry和Cancel。

MB_YESNO:消息框含有两个按钮:Yes和No。

MB_YESNOCANCEL:消息框含有三个按钮:Yes,No和Cancel。

指定下列标志中的一个来显示消息框中的图标:标志的含义如下。

MB_ICONEXCLAMATION:

MB_ICONWARNING:一个惊叹号出现在消息框。

MB_ICONINFORMATION:

MB_ICONASTERISK:一个圆圈中小写字母i组成的图标出现在消息框。

MB_ICONOUESTION:一个问题标记图标出现在消息框。

MB_ICONSTOP:

MB_ICONERROR:

MM_ICONHAND:一个停止消息图标出现在消息框。

指定下列标志中的一个来显不缺省的按钮:标志的含义如下。

MB_DEFBUTTON1:第一个按钮为缺省按钮。如果MB_DEFBUTTON2,MB_DEFBUTTON3,MB_DEFBUTTON4没有被指定,则MB_DEFBUTTON1为缺省值。

MB_DEFSUTTON2;第二个按钮为缺省按钮。

MB_DEFBUTTON3:第三个按钮为缺省按钮。

MB_DEFBUTTON4:第四个按钮为缺省按钮。

指定下列标志中的一个来显示对话框的形态:标志的含义如卜。

MB_APPLMODAL:在hwnd参数标识的窗口中继续工作以前,用户一定响应消息框。但是,用户可以移动到其他线程的窗口且在这些窗口中工作。根据应用程序中窗口的层次机构,用户则以移动到线程内的其他窗口。所有母消息框的子窗口自动地失效,但是弹出窗口不是这样。如果既没有指定MB_SYSTEMMODAL也没有指定MB_TASKMOOAL,则MB_APPLMODAL为缺省的。

MB_SYSTEMMODAL:除了消息框有WB_EX_TOPMOST类型,MB_APPLMODAL和WS_EX_TOPMOST一样。用系统模态消息框来改变各种各样的用户,主要的损坏错误需要立即注意(例如,内存溢出)。如果不是那些与hwnd联系的窗口,此标志对用户对窗口的相互联系没有影响。

MB_TASKMODAL:如果参数hwnd为NULL,除了所有属于当前线程高层次的窗口足失效的,MB_TASKMODALL和MB_ApPLMODAL一样。当调用应用程序或库没有一个可以得到的窗口句柄时,使用此标志。但仍需要阻止到调用应用程序甲其他窗口的输入而不是搁置其他线程。

另外,可以指定下列标志。

MB_DEFAULT_DESKTOP_ONLy:接收输入的当前桌面一定是一个缺省桌面。否则,函数调用失败。缺省桌面是一个在用户已经纪录且以后应用程序在此上面运行的桌面。

MB_HELP:把一个Help按钮增加到消息框。选择Help按钮或按F1产生一个Help事件。

MB_RIGHT:文本为右调整。

MB_RTLREADING:用在Hebrew和Arabic系统中从右到左的顺序显示消息和大写文本。

MB_SETFOREGROUND:消息框变为前景窗口。在内部系统为消息个调用SetForegrundWindow函数。

MB_TOPMOSI:消息框用WS_EX_TOPMOST窗口类型来创建MB_SERVICE_NOTIFICATION。

我有本API的大全,你可以查查


本文发布于:2023-02-28 19:42:00,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/zhishi/a/167762955466540.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:messagebox函数.doc

本文 PDF 下载地址:messagebox函数.pdf

上一篇:360 卸载
下一篇:返回列表
标签:函数   messagebox
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 实用文体写作网旗下知识大全大全栏目是一个全百科类宝库! 优秀范文|法律文书|专利查询|