最佳答案
我们先看一下MessageBox函数的声明
int iStdCall MessageBoxA(iHWnd hWnd,icchar* lpText,icchar* lpCaption,iuint uType);
参数中hWnd为父窗口的句柄
我们先看一下MessageBox函数的声明
int iStdCall MessageBoxA(iHWnd hWnd,icchar* lpText,icchar* lpCaption,iuint uType);
参数中hWnd为父窗口的句柄
lpText为消息框的显示的消息
lpCaption为消息框的窗口标题
uType指定一个决定对话框的内容和行为的位标志集,这个参数中最好要包含iMb_SystemModal,不然在点击主窗口其他地方点击后,这个弹出的窗口会被隐藏到背后。uType包含了众多标志:
//消息框中的按钮To indicate the buttons displayed in the message box, specify one of the following values.
#define iMb_Ok0x00000000L//消息框含有一个按钮:OK.这是缺省值.The message box contains one push button: OK. This is the default.
#define iMb_OkCancel0x00000001L//消息框含有两个按钮:OK和Cancel,The message box contains two push buttons: OK and Cancel.
#define iMb_AbortRetryIgnore0x00000002L//消息框含有三个按钮:Abort,Retry和Ignore,The message box contains three push buttons: Abort, Retry, and Ignore.
#define iMb_YesNoCancel0x00000003L//消息框含有三个按钮:Yes,No和Cancel,The message box contains three push buttons: Yes, No, and Cancel.
#define iMb_YesNo0x00000004L//消息框含有两个按钮:Yes和No,The message box contains two push buttons: Yes and No.
#define iMb_RetryCancel0x00000005L//消息框含有两个按钮:Retry和Cancel,The message box contains two push buttons: Retry and Cancel.
#define iMb_CancelTryContinue0x00000006L//Microsoft Windows 2000/XP: The message box contains three push buttons: Cancel, Try Again, Continue. Use this message box type instead of MB_ABORTRETRYIGNORE.
#define iMb_Help0x00004000L//把一个Help按钮增加到消息框.选择Help按钮或按F1产生一个Help事件.Windows 95/98/Me, Windows NT 4.0 and later: Adds a Help button to the message box. When the user clicks the Help button or presses F1, the system sends a WM_HELP message to the owner.
//消息框中的图标To display an icon in the message box, specify one of the following values.
#define iMb_IconHand0x00000010L//一个停止消息图标出现在消息框 A stop-sign icon appears in the message box.
#define iMb_IconErroriMb_IconHand
#define iMb_IconStopiMb_IconHand
#define iMb_IconQuestion0x00000020L//一个问题标记图标出现在消息框 A question-mark icon appears in the message box. The question mark message icon is no longer recommended because it does not clearly represent a specific type of message and because the phrasing of a message as a question could apply to any message type. In addition, users can confuse the message symbol question mark with Help information. Therefore, do not use this question mark message symbol in your message boxes. The system continues to support its inclusion only for backward compatibility.
#define iMb_IconExclamation0x00000030L//一个惊叹号出现在消息框An exclamation-point icon appears in the message box.
#define iMb_IconWarningiMb_IconExclamation
#define iMb_IconAsterisk0x00000040L//一个圆圈中小写字母i组成的图标出现在消息框An icon consisting of a lowercase letter i in a circle appears in the message box.
#define iMb_IconInformationiMb_IconAsterisk
#define iMb_UserIcon0x00000080L//
//消息框中的按钮 To indicate the default button, specify one of the following values.
#define iMb_DefButton10x00000000L//第一个按钮为缺省按钮.缺省值 The first button is the default button. MB_DEFBUTTON1 is the default unless MB_DEFBUTTON2, MB_DEFBUTTON3, or MB_DEFBUTTON4 is specified.
#define iMb_DefButton20x00000100L//第二个按钮为缺省按钮The second button is the default button.
#define iMb_DefButton30x00000200L//第三个按钮为缺省按钮The third button is the default button.
#define iMb_DefButton40x00000300L//第四个按钮为缺省按钮The fourth button is the default button.
//对话框的形态 To indicate the modality of the dialog box, specify one of the following values.
#define iMb_AppLModal0x00000000L//在hwnd参数标识的窗口中继续工作以前,用户一定响应消息框.但是,用户可以移动到其他线程的窗口且在这些窗口中工作.根据应用程序中窗口的层次机构,用户则以移动到线程内的其他窗口.所有母消息框的子窗口自动地失效,但是弹出窗口不是这样.如果既没有指定iMb_SystemModal也没有指定MB_TASKMOOAL,则iMb_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 threads 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 thread. 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.
#define iMb_SystemModal0x00001000L//除了消息框有WB_EX_TOPMOST类型,iMb_AppLModal和iWs_Ex_TopMost一样.用系统模态消息框来改变各种各样的用户,主要的损坏错误需要立即注意(例如,内存溢出).如果不是那些与hwnd联系的窗口,此标志对用户对窗口的相互联系没有影响.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.
#define iMb_TaskModal0x00002000L//如果参数hwnd为iNull,除了所有属于当前线程高层次的窗口足失效的,MB_TASKMODALL和MB_ApPLMODAL一样.当调用应用程序或库没有一个可以得到的窗口句柄时,使用此标志.但仍需要阻止到调用应用程序甲其他窗口的输入而不是搁置其他线程.Same as MB_APPLMODAL except that all the top-level windows belonging to the current thread 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 calling thread without suspending other threads.
//另外还可以增加以下标志:To specify other options, use one or more of the following values.
#define iMb_NoFocus0x00008000L//
#define iMb_SetForeground0x00010000L//消息框变为前景窗口.在内部系统为消息个调用SetForegrundWindow函数 The message box becomes the foreground window. Internally, the system calls the SetForegroundWindow function for the message box.
#define iMb_Default_Desktop_Only0x00020000L//接收输入的当前桌面一定是一个缺省桌面.否则,函数调用失败.缺省桌面是一个在用户已经纪录且以后应用程序在此上面运行的桌面 Windows NT/2000/XP: Same as MB_SERVICE_NOTIFICATION except that the system will display the message box only on the default desktop of the interactive window station. For more information, see Window Stations. Windows NT 4.0 and earlier: If the current input desktop is not the default desktop, MessageBox fails. Windows 2000/XP: If the current input desktop is not the default desktop, MessageBox does not return until the user switches to the default desktop. Windows 95/98/Me: This flag has no effect.
#define iMb_TopMost0x00040000L//消息框用iWs_Ex_TopMost窗口类型来创建iMb_Service_Notification,The message box is created with the WS_EX_TOPMOST window style.
#define iMb_Right0x00080000L//文本为右调整 The text is right-justified.
#define iMb_RtlReading0x00100000L//用在Hebrew和Arabic系统中从右到左的顺序显示消息和大写文本 Displays message and caption text using right-to-left reading order on Hebrew and Arabic systems.
#define iMb_Service_Notification 0x00200000L//Windows NT/2000/XP: 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. Terminal Services: If the calling thread has an impersonation token, the function directs the message box to the session specified in the impersonation token. 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 more information on the changes between Microsoft Windows NT 3.51 and Windows NT 4.0, see Remarks.
#define iMb_Service_Notification_Nt3X 0x00040000L//Windows NT/2000/XP: This value corresponds to the value defined for MB_SERVICE_NOTIFICATION for Windows NT version 3.51.
#define iMb_TypeMask0x0000000FL//
#define iMb_IconMask0x000000F0L//
#define iMb_DefMask0x00000F00L//
#define iMb_ModeMask0x00003000L//
#define iMb_MiscMask0x0000C000L//
//如果没有足够的内存来创建消息框,返回零.成功返回值为下列中的一个: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. If the function fails, the return value is zero. To get extended error information, call GetLastError. If the function succeeds, the return value is one of the following menu-item values.
#define iIdOk1//OK按钮被选中OK button was selected.
#define iIdCancel2// Cancel button was selected.
#define iIdAbort3// Abort button was selected.
#define iIdRetry4//RETRY按钮被选中Retry button was selected.
#define iIdIgnore5//Ignore button was selected.
#define iIdYes6//Yes button was selected.
#define iIdNo7//NO按钮被选中No button was selected.
#define iIdClose8//
#define iIdHelp9//
#define iIdTryAgain10//Try Again button was selected.
#define iIdContinue11//Continue button was selected.
#define iIdTimeOut32000//
鉴于MessageBox的参数众多,很多参数我们不是经常使用,所以我们对常用的参数做了一个简化定义。主要定义了以下几个常用参数:
1、voidXiaoXi1(iHWnd hwnd, mchar *neirong )与 voidXiaoXi6( mchar *neirong )很简单的显示一个提示消息,标题和内容一样,如
XiaoXi1( g_hwnd, "我是提示消息");
XiaoXi6( "我是提示消息" );
![](https://bj.bcebos.com/baidu-rmb-video-cover-1/4551113b2c9ab07a48da4608eab1e16e.jpeg)
2、void XiaoXi1(iHWnd hwnd, mchar *neirong, mchar *biaoti )与void XiaoXi6( mchar *neirong, mchar *biaoti ) 也是简单显示一个提示消息,标题和内容分开,如
XiaoXi1( g_hwnd, "提示消息内容","提示消息标题" );
XiaoXi6( "提示消息内容","提示消息标题" );
3、带有选择的提示窗口ibol XiaoXi22(iHWnd hwnd, mchar *neirong, mchar *biaoti )和ibol XiaoXi21(iHWnd hwnd, mchar *neirong, mchar *biaoti ),这两个分别带有选择是否与Ok、Cancel按钮的提示窗口,当选择Yes与Ok时返回1,其他返回0.