messagebox函数,Pb中messagebox()的五个参数的求法和参数的作用分别是什么?
messagebox函数,Pb中messagebox()的五个参数的求法和参数的作用分别是什么?详细介绍
本文目录一览: MessageBox函数
自己写一个格式化MessageBox嘛:
#include
#include
#include
int CDECL MessageBoxPrintf(TCHAR * szCaption, TCHAR * szFormat, ...)
{
va_list pArgList;
va_start(pArgList, szFormat);
TCHAR szBuffer[1024];
_vsntprintf_s(szBuffer, sizeof szBuffer / sizeof TCHAR, szFormat, pArgList);
va_end(pArgList);
return MessageBox(NULL, szBuffer, szCaption, MB_OK);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iShowCmd)
{
int year = 2007;
const TCHAR* greeting = "Hello!";
MessageBoxPrintf(TEXT("Message"), TEXT("%s This is year %d"), greeting, year);
}
或者使用wsprintf:
#include
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
TCHAR buffer[1024];
int year = 2007;
const TCHAR* month = TEXT("Apr.");
int day = 11;
wsprintf(buffer, TEXT("Today is: %d %s %d"), day, month, year);
MessageBox(NULL, buffer, TEXT("Data Report"), MB_OK | MB_ICONASTERISK);
}
MessageBox("数值:"+CurrentCommodityIndex,"提示",MB_ICONINFORMATION);
或者用一个指针.
MessageBox.Show(string.Format("{0}",CurrentCommodityIndex));
MessageBox 函数用于创建、显示并操作一个消息对话框。该对话框包含由调用程序定义的信息和标题,以及预先定义的图标和按钮。
定义(适用于Visual Basic 6.0):Declare Function MessageBox Lib "user32" 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
//切记!当调用
时,不要调用MFC!(Afx.h)
int main()
{
int result = MessageBox( NULL , TEXT("这是对话框") , TEXT("你好") , MB_ICONINFORMATION|MB_YESNO);
switch(result)/*注意!使用Unicode应用TEXT包围字串*/
{
case IDYES:MessageBox(NULL,TEXT("您选择了YES"),TEXT("YES"),MB_OK);break;
case IDNO:MessageBox(NULL,TEXT("您选择了NO"),TEXT("NO"),MB_OK);break;
}
return 0;
}
关于vb程序下messagebox的使用
msgbox"请等待"(提升的内容),0,(代表提示的是什么符号如!?)"提示"(这个提示是提示框的标题。
MsgBox "Hello world", vbCritical + vbSystemModal + vbMsgBoxHelpButton + vbMsgBoxRight, "my new file"
参考文献:http://zhidao.baidu.com/question/87866806.html
MsgBox 函数,在对话框中显示消息,等待用户单击按钮,并返回一个 Integer 告诉用户单击哪一个按钮。
语法
设置值
MsgBox 函数示例
本示例使用 MsgBox 函数,在具有“是”及“否”按钮的对话框中显示一条严重错误信息。示例中的缺省按钮为“否”,MsgBox 函数的返回值视用户按哪一个钮而定。本示例假设 DEMO.HLP 为一帮助文件,其中有一个内容代码为 1000。
Private Sub Form_Click() Dim Msg, Style, Title, Help, Ctxt, Response, MyString Msg = "Do you want to continue ?" ' 定义信息。 Style = vbYesNo + vbCritical + vbDefaultButton2 ' 定义按钮。 Title = "MsgBox Demonstration" ' 定义标题。 Help = "DEMO.HLP" ' 定义帮助文件。 Ctxt = 1000 ' 定义标题 ' 上下文。 ' 显示信息。 Response = MsgBox(Msg, Style, Title, Help, Ctxt) If Response = vbYes Then ' 用户按下“是”。 MyString = "Yes" ' 完成某操作。 Else ' 用户按下“否”。 MyString = "No" ' 完成某操作。 End IfEnd Sub
将上述代码中Msg = "Do you want to continue ?" 改为:Msg = "Hello world!"就可以满足要求。
请问:VB 里面的MessageBox要怎么用,整个函数是什么样的?
不知道你说的是不是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
vbIgnore 5 Ignore
vbYes 6 Yes
vbNo 7 No
说明
在提供了 helpfile 与 context 的时候,用户可以按 F1 来查看与 context 相应的帮助主题。像 Microsoft Excel 这样一些主机应用程序也会在对话框中自动添加一个 Help 按钮。
如果对话框显示 Cancel 按钮,则按下 ESC 键与单击 Cancel 按钮的效果相同。如果对话框中有 Help 按钮,则对话框中提供有上下文相关的帮助。但是,直到其它按钮中有一个被单击之前,都不会返回任何值。
注意 如果还要指定第一个命名参数以外的参数,则必须在表达式中使用 MsgBox。为了省略某些位置参数,必须加入相应的逗号分界符。
MessageBox.Show("aaaaaaaaaaaaaaaaaaaaa")
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
vbIgnore 5 Ignore
vbYes 6 Yes
vbNo 7 No
说明
在提供了 helpfile 与 context 的时候,用户可以按 F1(Windows) or HELP (Macintosh) 来查看与 context 相应的帮助主题。像 Microsoft Excel 这样一些主应用程序也会在对话框中自动添加一个 Help 按钮。
如果对话框显示 Cancel 按钮,则按下 ESC 键与单击 Cancel 按钮的效果相同。如果对话框中有 Help 按钮,则对话框中提供有上下文相关的帮助。但是,直到其它按钮中有一个被单击之前,都不会返回任何值。
注意 如果还要指定第一个命名参数以外的参数,则必须在表达式中使用 MsgBox。为了省略某些位置参数,必须加入相应的逗号分界符。
VS2010 的问题 MFC 中 MessageBox()用法
注意!vc++2010默认是unicode编码!MessageBox(NULL,_T("我要分啊"),_T("提示"),MB_OK),其中第一个参数是窗口句柄!如何要用多字节方式,MessageBoxA(NULL,"楼主好人","提示",MB_OK),如果不习惯后一种还可以改默认编码,解决方案上单击右键属性->配置属性->常规->字符集->多字节字符集,楼主我一个个自打出来的,你看着办吧
{ if(FindWindow(NULL,L"我的电脑")!=NULL) MessageBox(L"我的电脑运行说明:这个程序在vs2010中编译成功,使用的是MFC环境其中OnBnClickedButton1()
function MessageBox(hWnd: HWND; Text, Caption: PChar; Type: Word): Integer;
hWnd:对话框父窗口句柄,对话框显示在Delphi窗体内,可使用窗体的Handle属性,否则可用0,使其直接作为桌面窗口的子窗口。
Text:欲显示的信息字符串。
Caption:对话框标题字符串。
Type:对话框类型常量。
该函数的返回值为整数,用于对话框按钮的识别。
参考用法如下:
1. MessageBox("这是一个最简单的消息框!");
2. MessageBox("这是一个有标题的消息框!","标题");
3. MessageBox("这是一个确定 取消的消息框!","标题", MB_OKCANCEL );
4. MessageBox("这是一个警告的消息框!","标题", MB_ICONEXCLAMATION );
5. MessageBox("这是一个两种属性的消息框!","标题",
MB_ICONEXCLAMATION|MB_OKCANCEL );
6. if(MessageBox("一种常用的应用","标题
" ,MB_ICONEXCLAMATION|MB_OKCANCEL)==IDCANCEL)
return;
注意:
以上消息框的用法是在CWnd的子类中的应用,如果不是,则要MessageBox(NULL,"ddd","ddd",MB_OK); 或MessageBox(hWnd,"ddd","ddd",MB_OK); hWnd为某窗口的句柄,或者直接用AfxMessageBox。
52. 在VFP中,Messagebox()函数的返回值为5,表用户选择什么按钮?
在Visual FoxPro中,当MessageBox()函数的返回值为 5 时,表示用户选择的是 "仅确定" 按钮。
'MessageBox()'函数用于在 Visual FoxPro 程序中显示消息对话框,用户可以通过对话框中的按钮进行选择,该函数的返回值根据用户的选择而变化,以表示用户的操作。如下所示是一些常见的返回值及其含义:
1:确定
2:取消
3:忽略
4:重试
5:仅确定
您可以通过使用常量定义来指定消息对话框的显示内容,例如:
RETURN MESSAGEBOX("是否继续操作?", MB_YESNO + MB_ICONQUESTION)
在此代码中,显示的消息对话框将具有"是"和"否"按钮,并显示问号图标。
C语言MessageBox问题
用MessageBox()的返回值判断,返回值含意如下:
IDABORT:Abort 按钮被选中。
IDCANCEL:Cancel按钮被选中。
IDIGNORE:Ignore按钮被选中。
IDNO:NO按钮被选中。
IDOK:OK按钮被选中。
IDRETRY:RETRY按钮被选中。
IDYES:YES按钮被选中。
***************************************************
示例:
#include "windows.h"
int main()
{int i;
i=MessageBox(NULL,"do you?","baby",MB_YESNO);
if(i==IDYES)MessageBox(NULL,"e","e",MB_OK);/*如果点击了“是”*/
else
MessageBox(NULL,"a","a",MB_OK);/*否则*/
return 0;
}
消息框的函数原型:
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(第一个)按钮上
MessageBox()是Win32 API函数,他的返回值是0 1 2 4 8
MessageBox(NULL,"do you?","baby",MB_YESNO);
里点击是返回0 点击否返回1
1、MessageBox(),注意区分大小写。它的功能是弹出一个标准的Windows对话框。它不是C函数库的标准函数,而是WINDNWS API函数,但是可以用C语言调用API函数。
下面举例,显示出一个对话框,其标题为Hello,内容为Hello World,包含一个【确定】按钮:
#include
int main()
{
MessageBox(NULL,"Hello World","Hello",MB_OK);
return 0;
}
//代码在VC6.0下编译通过
2、MessageBox()函数第一个参数是窗口句柄,第二个是窗口内容字符串,第三个是窗口标题字符串,第四个是窗口所包含的按钮类型;函数返回值为int类型,用于判断用户点击了哪个按钮。
简单介绍一下第四个参数(左边参数,右边按钮):
MB_OK 确定
MB_OKCANCEL 确定 取消
MB_YESNO 是 否
MB_RETRY 重试
还可以在窗口显示通知图标:
MB_OK|MB_ICONQUESTION 确定 问号
依此类推,只要在后面加“|”然后是图标代号。
MB_ICONEXCLAMATION 感叹号
MB_ICONERROR 错误
MB_ICONINFORMATION 信息
C语言中messagebox的用法
#include
int main(void)
{
MessageBox(NULL, "你好(内容)", "对话框(标题)", MB_OK);
return 0;
}//end main
MessageBox(),注意区分大小写。
它的功能是弹出一个标准的Windows对话框。它不是C函数库的标准函数,而是WINDNWS
API函数,但是可以用C语言调用API函数。
下面举例,显示出一个对话框,其标题为Hello,内容为Hello
World,包含一个【确定】按钮:
#include
int
main()
{
MessageBox(NULL,"Hello
World","Hello",MB_OK);
return
0;
}
调用windows API 函数就好了
消息框的函数原型:
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(第一个)按钮上
Pb中messagebox()的五个参数的求法和参数的作用分别是什么?
MessageBox()
功能显示一个消息对话框。
语法MessageBox(title,text{,icon{,button{,default}}})
参数
title:string类型,指定消息对话框的标题
text:指定消息对话框中显示的消息,该参数可以是数值数据类型、字符串或boolean值
icon:Icon枚举类型,可选项,指定要在该对话框左侧显示的图标
button:Button枚举类型,可选项,指定显示在该对话框底部的按钮
default:数值型,可选项,指定作为缺省按钮的按钮编号,按钮编号自左向右依次计数,缺省值为1,如果该参数指定的编号超过了显示的按钮个数,那么MessageBox()函数将使用缺省值返回值Integer。
函数执行成功时返回用户选择的按钮编号(例如1、2、3等),发生错误时返回-1。如果任何参数的值为NULL,MessageBox()函数返回NULL。
用法当你的应用程序需要显示一段简短信息(比如显示出错、警告等信息)时,没有必要自己从头创建窗口、安排控件,使用MessageBox()函数既简单又方便。用户只有响应该窗口后,程序才能继续运行下去。
MessageBox()函数的icon参数指定显示在窗口中的图标,它是枚举类型,可能取值为:
取值
图标Information!
StopSign!
Exclamation!
Question!
None!
无图标,其中Information!是Icon参数的缺省值。
Button参数指定在窗口中显示哪些按钮,有效取值为:取值中文Windows
95下显示
OK!“确定”按钮
OKCancel!“确定”、“取消”按钮
YesNo!“是”、“否”按钮
YesNoCancel!“是”、“否”、“取消”按钮
RetryCancel!“重试”、“取消”按钮
AbortRetryIgnore!“终止”、“重试”、“忽略”按钮
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 user32 Alias MessageBoxA (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As LongParameters:?hWndIdentifies the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window.?lpTextPoints to a null-terminated string containing the message to be displayed.?lpCaptionPoints to a null-terminated string used for the dialog box title. If this parameter is NULL, the default title Error is used.?uTypeSpecifies 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:MB_ABORTRETRYIGNOREThe message box contains three push buttons: Abort, Retry, and Ignore.MB_OKThe message box contains one push button: OK. This is the default.MB_OKCANCELThe message box contains two push buttons: OK and Cancel.MB_RETRYCANCELThe message box contains two push buttons: Retry and Cancel.MB_YESNOThe message box contains two push buttons: Yes and No.MB_YESNOCANCELThe 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_ICONWARNINGAn exclamation-point icon appears in the message box.MB_ICONINFORMATION, MB_ICONASTERISKAn icon consisting of a lowercase letter i in a circle appears in the message box.MB_ICONQUESTIONA question-mark icon appears in the message box.MB_ICONSTOP,MB_ICONERROR,MB_ICONHANDA stop-sign icon appears in the message box.Specify one of the following flags to indicate the default button:MB_DEFBUTTON1The first button is the default button.MB_DEFBUTTON1 is the default unless MB_DEFBUTTON2, MB_DEFBUTTON3, or MB_DEFBUTTON4 is specified.MB_DEFBUTTON2The second button is the default button.MB_DEFBUTTON3The third button is the default button.MB_DEFBUTTON4The fourth button is the default button.Specify one of the following flags to indicate the modality of the dialog box:MB_APPLMODALThe user must respond to the message box before continuing work in the window identified by the hWnd parameter. However, the user can move to the windows of other applications and work in those windows.Depending on the hierarchy of windows in the application, the user 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_SYSTEMMODALSame as MB_APPLMODAL except that the message box has the WS_EX_TOPMOST style. Use system-modal message boxes to notify the user of serious, potentially damaging errors that require immediate attention (for example, running out of memory). This flag has no effect on the user's ability to interact with windows other than those associated with hWnd.MB_TASKMODALSame as MB_APPLMODAL except that all the top-level windows belonging to the current task are disabled if the hWnd parameter is NULL. Use 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_ONLYThe desktop currently receiving input must be a default desktop; otherwise, the function fails. A default desktop is one an application runs on after the user has logged on.MB_HELPAdds a Help button to the message box. Choosing the Help button or pressing F1 generates a Help event.MB_RIGHTThe text is right-justified.MB_RTLREADINGDisplays message and caption text using right-to-left reading order on Hebrew and Arabic systems.MB_SETFOREGROUNDThe message box becomes the foreground window. Internally, Windows calls the SetForegroundWindow function for the message box.MB_TOPMOSTThe message box is created with the WS_EX_TOPMOST window style.MB_SERVICE_NOTIFICATIONWindows NT only: The caller is a service notifying the user of an event. The function displays a message box on the current active desktop, even if there is no user logged on to the computer.If this flag is set, 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 services 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 set by the linker, less than 4.0.To build a service that uses 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; or2. At link-time, specify version 4.0. At run-time, use the GetVersionEx function to check the system version. Then when running on Windows NT 3.x, use MB_SERVICE_NOTIFICATION_NT3X; and on Windows NT 4.0, use MB_SERVICE_NOTIFICATION.MB_SERVICE_NOTIFICATION_NT3XWindows 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:IDABORTAbort button was selected.IDCANCELCancel button was selected.IDIGNOREIgnore button was selected.IDNONo button was selected.IDOKOK button was selected.IDRETRYRetry button was selected.IDYESYes 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.程序示例:#include
#include
int main ( int argc , char *argv[] ){//调用API函数MessageBoxint nSelect=::MessageBox(NULL,正文:Hello World,标题:MessageBox程序示例,MB_OKCANCEL | MB_ICONINFORMATION | MB_DEFBUTTON1 );//API函数前加“::”符号,表示这是一个全局的函数,以与c++类的成员函数相区分if( IDOK == nSelect ){printf(您按了“确定”\n);}else{printf(您按了“取消”\n);}return 0;}
请问一下VC++2010如何在dll里实现弹出消息框?
在VC++2010中,可以使用MessageBox函数在DLL中实现弹出消息框。该函数位于Windows API中,可以在用户界面中显示消息框并等待用户响应。以下是一个示例代码:
```c++
#include
// 导出函数
extern "C" __declspec(dllexport) void ShowMessageBox()
{
MessageBox(NULL, "Hello, World!", "Message", MB_OK);
}
```
在上述代码中,使用了__declspec(dllexport)关键字来导出ShowMessageBox函数。该函数使用MessageBox函数来显示消息框,其中第一个参数为父窗口句柄,这里置为NULL表示使用默认的父窗口;第二个参数为消息框显示的文本内容;第三个参数为消息框的标题;第四个参数为消息框的样式,这里设置为MB_OK表示显示一个OK按钮。
在使用该DLL的应用程序中,可以使用LoadLibrary函数加载该DLL,并使用GetProcAddress函数获取ShowMessageBox函数的入口地址。然后调用该函数即可显示消息框。