如何修改Messagebox修改对话框标题的标题

2013年7月 VC/MFC大版内专家分月排行榜第三2011年12月 VC/MFC大版内专家分月排行榜第三
2012年12月 总版技术专家分月排行榜第一2012年10月 总版技术专家分月排行榜第一2012年9月 总版技术专家分月排行榜第一2012年8月 总版技术专家分月排行榜第一
2012年11月 总版技术专家分月排行榜第三
2012年4月 VC/MFC大版内专家分月排行榜第一
2012年5月 VC/MFC大版内专家分月排行榜第二2012年3月 VC/MFC大版内专家分月排行榜第二2011年7月 VC/MFC大版内专家分月排行榜第二2011年1月 VC/MFC大版内专家分月排行榜第二2010年12月 VC/MFC大版内专家分月排行榜第二2010年9月 VC/MFC大版内专家分月排行榜第二2010年6月 VC/MFC大版内专家分月排行榜第二2010年5月 VC/MFC大版内专家分月排行榜第二2010年4月 VC/MFC大版内专家分月排行榜第二
本帖子已过去太久远了,不再提供回复功能。c#消息提示框messagebox的详解及使用
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了c#消息提示框messagebox的详解及使用的相关资料,需要的朋友可以参考下
C#消息提示框messagebox的详解及使用
消息对话框是用messagebox对象的show方法显示的。MessageBox对象是命名空间System.Windows.Forms的一部分,Show是一个静态方法,意思是说,不需要基于MessageBox类的对象创建实例,就可以使用该方法。而且该方法是可以重载的,即方法可以有不同的参数列表形式。
返回结果:DialogResult dr1=MessageBox.Show(text,caption,buttons,icon,defaultbutton,option);
不返回任何值:MessageBox.Show(text,caption,buttons,icon);
参数必须按照上面顺序输出
1,Text:设置消息对话框中的提示文本语句.必须是String类型
2,Caption:可选参数,设置消息对话框的标题,必须是字符串型
3,Buttons:可选参数,设置消息对话框中显示哪些按钮
4,Icon:可选参数,设置消息对话框中显示哪个图标
5,Defaultbutton:可选参数,设置消息对话框哪个按钮是默认激活的
6,Option可选参数,为消息对话框设置一些特殊的选项,如文本对齐方式,指定阅读顺序,是否向系统日志写消息
Button 各枚举常量及意义
&消息框中只有"确定"按钮
&消息框中只有"确定"和"取消"按钮
&消息框中只有"是"和"否"按钮
&YesNoCancel
&消息框中有"是","否"和"取消"按钮
&RetryCancel
&消息框中有"重试"和"取消"按钮
&AbortRetryIgnore
&消息框中有"中止","重试"和"忽略"按钮
&功能及意义
Icon各枚举常量及意义
&消息框中有一个符号,由一个红色背景的圆圈及其中的白色X组成
&该符号是由一个圆圈及其中的小写字母i组成
&Exclamation
&该符号由一个黄色背景的三角形及其中的一个叹号组成
&该符号由一个红色背景的圆圈及其中的白色x组成
&该符号由一个圆圈及其中的一个问号组成
&消息框中不包含符号
&Information
&该符号是由一个圆圈及其中的小写字母i组成
&该符号是由一个红色背景的圆圈及其中的白色X组成
该符号是由一个黄色背景的三角形及其中的一个叹号组成
消息对话框的返回值是System.Windows.Forms.DialogResult的成员,各枚举常量及意义如下表
&消息框的返回值是"中止"(Abort),即单击了"中止"按钮
&消息框的返回值是"取消"(Cancel),即单击了"取消"按钮
&消息框的返回值是"忽略"(Ignore),即单击了"忽略"按钮
&消息框的返回值是"否"(No),即单击了"否"按钮
&消息框的返回值是"确定"(Ok),即单击了"确定"按钮
&消息框的返回值是"重试"(Retry),即单击了"重试"按钮
&消息框没有任何返回值,即没有单击任何按钮
&消息框的返回值是"是"(Yes),即单击了"是"按钮
1、 /* if (flag)
DialogResult diagorel = MessageBox.Show(this, "Please inpult again,your message is empty!", "Information cue", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning);
switch (diagorel)
case DialogResult.Retry:
this.username.Text = "";
this.password.Text = "";
case DialogResult.Cancel:
2、最简单的方法就是这样
if( MessageBox.Show( "确定提交吗?", "提示", MessageBoxButtons.YesNo ) == DialogResult.Yes )
程序运行代码.......
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具MessageBox函数_百度百科
声明:百科词条人人可编辑,词条创建和修改均免费,绝不存在官方及代理商付费代编,请勿上当受骗。
MessageBox函数
本词条缺少名片图,补充相关内容使词条更完整,还能快速升级,赶紧来吧!
MessageBox 函数用于创建、显示并操作一个消息对话框。该对话框包含由调用程序定义的信息和标题,以及预先定义的图标和按钮。
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
MessageBox函数参数说明
指定该对话框的所有者窗口。如果该参数为空(0),则该对话框不属于任何窗口(?)。
显示在对话框中的消息。
lpCaption:
在对话框中显示的字符串。如果该参数为空(vbNullString),则使用默认的“错误”作为对话框的标题。
指定显示按钮的数目及形式,使用的图标样式,缺省按钮是什么以及的强制回应等。可以为下列常数之一或某几个数值相加的和。
指定按钮样式:
MB_ABORTRETRYIGNORE
显示 Abort、Retry 及 Ignore 按钮。
只显示 OK 按钮。(默认)
MB_OKCANCEL
显示 OK 及 Cancel 按钮。
MB_RETRYCANCEL
显示 Retry 及 Cancel 按钮。
显示 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
将Help按钮添加到消息框。
文本为右对齐。
MB_RTLREADING
指定文本应为在希伯来和阿拉伯语系统中的从右到左显示。
MB_SETFOREGROUND
指定窗口作为前景窗口。
MB_TOPMOST
MB_SERVICE_NOTIFICATION
MB_SERVICE_NOTIFICATION_NT3X
MB_SERVICE_NOTIFICATION
如果没有足够内存创建消息对话框,则返回0。
如果函数成功运行,则返回下列数值之一:
用户点击了 Abort 按钮。
用户点击了 Cancel 按钮。
用户点击了 Ignore 按钮。
用户点击了 No 按钮。
用户点击了 OK 按钮。
用户点击了 Retry 按钮。
用户点击了 Yes 按钮。
如果对话框显示 Cancel 按钮,则按下 ESC 键与单击 Cancel 按钮的效果相同。
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 Long
Parameters:
Identifies the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window.
Points to a null-terminated string containing the message to be displayed.
?lpCaption
Points to a null-terminated string used for the dialog box title. If this parameter is NULL, the default title Error is used.
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:
MB_ABORTRETRYIGNORE
The message box contains three push buttons: Abort, Retry, and Ignore.
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.
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 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:
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.
Specify one of the following flags to indicate the modality of the dialog box:
MB_APPLMODAL
The 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_SYSTEMMODAL
Same 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_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. 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_ONLY
The desktop currently receiving input must
otherwise, the function fails. A default desktop is one an application runs on after the user has logged on.
Adds a Help button to the message box. Choosing the Help button or pressing F1 generates a Help event.
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 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 . 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; or
2. 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_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:
Abort button was selected.
Cancel button was selected.
Ignore button was selected.
No button was selected.
OK button was selected.
Retry button was selected.
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.
程序示例:
#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(&您按了“确定”\n&);
printf(&您按了“取消”\n&);VC定制个性化的MessageBox解决方法
投稿:shichen2014
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了VC定制个性化的MessageBox解决方法,有助于进一步的了解windows应用程序的消息机制及运行原理,需要的朋友可以参考下
相信学过VC的人都知道MessageBox()函数的用法:
int MessageBox(
HWND hWnd,
// handle to owner window
LPCTSTR lpText,
// text in message box
LPCTSTR lpCaption, // message box title
UINT uType
// message box style
虽然在参数uType中可以指定一些样式,但你在程序中能够对MessageBox的外观所做的定义却不多。原因是当调用MessageBox()函数后,它在内部有自己的消息循环(所有的模式对话框都有自己的消息循环),返回时MessageBox对话框窗口已经被Destroy,所以你没有办法得到MessageBox对话框的窗口句柄。但你可以根据自己的不同需求用下面的方法中去定制你的MessageBox:
如果你只是想用自己的icon去代替系统MessageBox提供的那几种有限的icon,用MessageBoxIndirect()函数就可以了:
int MessageBoxIndirect(
CONST LPMSGBOXPARAMS lpMsgBoxParams // message box parameters
typedef struct {
HINSTANCE hI
DWORD_PTR dwContextHelpId;
MSGBOXCALLBACK lpfnMsgBoxC
dwLanguageId;
} MSGBOXPARAMS, *PMSGBOXPARAMS;
看到MSGBOXPARAMS结构中的lpszIcon吧,在使用过程中你应当准备一个合适的MSGBOXPARAMS结构,如果你要用自己的icon,你一定要用MB_USERICON这个flag。
上面我们也讲到不能定制MessageBox对话框的原因是没有办法得到它的窗口句柄,但我们真的没有办法了吗?当然有办法,那就是使用HOOK(钩子)机制。在windows系统中有多种HOOK,但在这里我们只用到HK_CBT类型的钩子。HK_CBT钩子过程在WM_MOVE、WM_SIZE、WM_ACTIVE、WM_CREATE、WM_DESTROY时被系统调用,所以HK_CBT钩子可以在这里用。下面让我们看如何实现MessageBox的定制过程。
1.安装HK_CBT钩子;
2.调用MessageBox()函数;
3.移除HK_CBT钩子。
整个过程很简单吧?我们在这里介绍第一步和第三步。
安装HK_CBT钩子:
HHOOK hMsgBoxHook = SetWindowsHookEx(
// Type of hook
// Hook procedure (see below)
// Module handle. Must be NULL (see docs)
GetCurrentThreadId()
// Only install for THIS thread!!!
重要的是SetWindowHookEx()函数的后边两个参数,用它可以区别安装是一个全局钩子还是一个线程钩子,在这里我们只要安装一个线程钩子。所以我们将Module handle设置为NULL,同时将thread ID设为本线程的ID。
在SetWindowHookEx()函数中有一个hook procedure,这是window调用的一个回调函数,在windows系统中有一个HOOK链,我们在编写hook procedure时要注意保证此链的完整,所以我们的hook procedure要调用CallNextHookEx()函数。下面就是我们的hook procedure:
LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
if(nCode & 0)
return CallNextHookEx(hMsgBoxHook, nCode, wParam, lParam);
switch(nCode)
case HCBT_ACTIVATE:
// 现在wParam中就是message box的句柄
hwnd = (HWND)wP
// 我们已经有了message box的句柄,在这里我们就可以定制message box了!
// Call the next hook, if there is one
return CallNextHookEx(hMsgBoxHook, nCode, wParam, lParam);
移除HK_CBT钩子:
只要调用UnhookWindowsHookEx()函数就可以了
好了,我们将在上面的三步写成一个函数,如下:
int MsgBoxEx(HWND hwnd, TCHAR *szText, TCHAR *szCaption, UINT uType)
// Install a thread hook, so we can customize it
hMsgBoxHook = SetWindowsHookEx(
GetCurrentThreadId()
// Display a standard message box
ret = MessageBox(hwnd, szText, szCaption, uType);
// remove the window hook
UnhookWindowsHookEx(hMsgBoxHook);
其实你也可以钩住WM_CREATE消息,不过那样处理要复杂一些。在早期的windows platform SDK中就有这样一个例子。
你可能说,定制一个MessageBox有什么用处,我想有下面的用途:
1.你可以用CreateWindowEx()给MessageBox添加一个check box控件,并子类化MessageBox来处理check box的消息
2.通过子类化改变messagebox、button或icon,以便和你整个程序的界面风格相一致
只要有了MessageBox对话框的句柄,你能做的很多,很多...
另外,如果你对模式对话框的机理很了解,你可以自己写出一个"MessageBox"来代替系统MessageBox用在你的程序中。你可以参考Jeffrey Richter的《Windows 95程式设计指南》,在书中给出了模式对话框的伪码。这本书的繁体电子版可以在候捷的个人网站上下载。这种方法也比较简单(添加一个消息循环,Enable/Disable Owner窗口),示例代码这里就不实现了。读者可以参考相关资料加以完善。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具以下试题来自:
填空题MESSAGEBox()函数的功能是显示一个用户自定义对话框。若未指定该对话框的标题,则对话框的默认标题为:(
) Microsoft Visual Foxpro
为您推荐的考试题库
你可能感兴趣的试题
1.填空题 数据流2.填空题 .F.3.填空题 等级考试4.填空题 .mem5.填空题 投影
热门相关试卷
最新相关试卷}

我要回帖

更多关于 设置对话框标题 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信