网站首页  词典首页

请输入您要查询的函数:

 

术语 messagebox
释义 MessageBox
语法:
int MessageBox( HWND hWnd,
LPCTSTR lpText,
LPCTSTR lpCaption,
UINT uType
);
MessageBox函数
显示一个模式对话框,其中包含如状态或错误的系统图标,按钮,以及一个简短的应用程序特定的信息,资料。消息框返回一个整数值,指示的按钮,用户点击。
参数
hWnd
[in]句柄消息框的所有者窗口被创建。如果该参数为NULL,则消息框没有所有者窗口。
lpText
[in]指向一个空结束的字符串,其中包含的信息显示。如果字符串的多行组成,您可以在各行之间用回车和/或每行之间的换行符。
lpCaption
[in]指向一个空结束的字符串,其中包含对话框的标题。如果该参数为NULL,则默认标题是错误。
uType
[in]指定的内容和对话框的行为。此参数可以是一个旗的旗以下群体的组合。
为了表示按钮显示在消息框中,指定下列值之一。
MB_ABORTRETRYIGNORE
该消息框包含三个按钮:中止,重试,和忽略。
MB_CANCELTRYCONTINUE
微软Windows 2000/XP的:该消息框包含三个按钮:取消,再试一次,继续。使用此消息框类型,而不是MB_ABORTRETRYIGNORE。
MB_HELP
Windows 95/98/Me中,Windows NT 4.0和更高版本:添加一个帮助按钮消息框。当用户单击帮助按钮或按F1,系统发送WM_HELP信息的主人。
MB_OK
该消息框包含一个按钮:确定。这是默认的。
MB_OKCANCEL
该消息框包含两个按钮:确定和取消。
MB_RETRYCANCEL
该消息框包含两个按钮:重试和取消。
MB_YESNO
该消息框包含两个按钮:是的,第
MB_YESNOCANCEL
该消息框包含三个按钮:是,否和取消。
要显示在消息框中的图标,指定下列值之一。
MB_ICONEXCLAMATION
感叹号点图标出现在消息框中。
MB_ICONWARNING
感叹号点图标出现在消息框中。
MB_ICONINFORMATION
一个图标的圆圈中的一个小写字母i组成的出现在消息框中。
MB_ICONASTERISK
一个图标的圆圈中的一个小写字母i组成的出现在消息框中。
MB_ICONQUESTION
问号图标出现在消息框中。在问号消息图标不再推荐,因为它没有清楚地代表了特定类型的信息,并因为作为信息措辞问题,适用于任何类型的消息。此外,用户可以通过帮助混淆信息消息的象征问号。因此,不要使用您的消息框这个问号消息的象征。该系统只支持继续将其列入为向后兼容。
MB_ICONSTOP
阿停止信号图标出现消息框。
MB_ICONERROR
阿停止信号图标出现消息框。
MB_ICONHAND
阿停止信号图标出现消息框。
为了表示默认的按钮,指定下列值之一。
MB_DEFBUTTON1
第一个按钮是默认按钮。
MB_DEFBUTTON1是,除非MB_DEFBUTTON2,MB_DEFBUTTON3,或MB_DEFBUTTON4是指定的默认。
MB_DEFBUTTON2
第二个按钮是默认按钮。
MB_DEFBUTTON3
第三个按钮是默认按钮。
MB_DEFBUTTON4
第四个按钮是默认按钮。
为了显示对话框的方式,指定下列值之一。
MB_APPLMODAL
用户必须响应消息框,然后继续在由hWnd参数确定的窗口工作。但是,用户可以移动到其他线程的窗户,在这些窗口工作。
根据不同层次的窗户在应用程序,用户可以在移动到其他窗口线程。的消息框的父母所有子窗口将自动禁用,但是弹出窗口不是。
MB_APPLMODAL是,如果不MB_SYSTEMMODAL也不MB_TASKMODAL是指定的默认。
MB_SYSTEMMODAL
作为MB_APPLMODAL相同,但该消息框有WS_EX_TOPMOST风格。使用系统模式消息框,通知用户的严重,可能造成损害的错误,需要立即注意(例如,内存不足)。此标志在用户的交互能力,窗户比hWnd有关的其他影响。
MB_TASKMODAL
作为MB_APPLMODAL相同,但所有顶层窗口属于当前线程被禁用,如果hWnd参数为NULL。使用此标志时,调用应用程序或库没有一个窗口句柄可用,但仍需要防止调用线程输入到其它窗口而暂停其他线程。
要指定其他选项,使用一个或多个下列值。
MB_DEFAULT_DESKTOP_ONLY
Windows NT/2000/XP的:一样的交互式窗口站桌面。有关更多信息,请参阅窗口站。
Windows NT 4.0和更早的版本:如果当前输入的桌面是不是默认的桌面,这些URL失败。
视窗2000/XP的:如果当前输入的桌面是不是默认的桌面上,这些URL不会返回,直到用户切换到默认桌面。
在Windows 95/98/Me:此标志无效。
MB_RIGHT
文本右对齐。
MB_RTLREADING
显示消息和标题文本使用从右到左阅读的希伯来语和阿拉伯语系统的秩序。
MB_SETFOREGROUND
该消息框成为前台窗口。在内部,系统要求在消息框中SetForegroundWindow函数。
MB_TOPMOST
该消息框创建的WS_EX_TOPMOST窗口样式。
MB_SERVICE_NOTIFICATION
Windows NT/2000/XP的:来电者是一种服务通知用户的事件。该函数显示了当前活动桌面消息框,即使在没有用户登录到计算机。
终端服务:如果调用线程模拟令牌,该函数指示消息框,在指定的模拟令牌了会议。
如果设置此标志的hWnd参数必须为NULL。这是这样的消息框可以出现在桌面上的桌面比相应由hWnd其他。
欲了解更多有关微软与Windows NT 3.51和Windows NT 4.0中,更改信息,请参见备注。
有关安全注意事项方面的信息使用此标志,见互动服务。特别是,要注意这个标志可以产生在锁定桌面上的交互式内容,因此应该只用于非常有限的情况下,如资源枯竭。
MB_SERVICE_NOTIFICATION_NT3X
Windows NT/2000/XP的:此值对应于用于Windows NT 3.51版MB_SERVICE_NOTIFICATION定义的值。
欲了解更多有关在Windows NT 3.51和Windows NT 4.0中,更改信息,请参见备注。
返回值
如果一个消息框有一个取消按钮,则函数返回IDCANCEL值如果不是Esc键被按下或取消按钮被选中。如果消息框没有取消按钮,按下ESC键无效。
如果函数失败,返回值是零。为了获得更多错误信息,调用GetLastError。
如果函数成功,返回值为下列其中一个菜单项的值。
IDABORTAbort按钮被选中。
IDCANCELCancel按钮被选中。
IDCONTINUEContinue按钮被选中。
IDIGNOREIgnore按钮被选中。
IDNONo按钮被选中。
IDOKOK按钮被选中。
IDRETRYRetry按钮被选中。
IDTRYAGAINTry再次按钮被选中。
IDYESYes按钮被选中。
备注
下面的系统图标可用于在一个消息框中通过设置uType参数相应的标志值:
IconFlag值
MB_ICONHAND,MB_ICONSTOP,或MB_ICONERROR
MB_ICONQUESTION
MB_ICONEXCLAMATION或MB_ICONWARNING
MB_ICONASTERISK或MB_ICONINFORMATION
增加两个从右到左马克(RLMs),根据Unicode格式字符U的一个MessageBox显示字符串开头200 F是由Win32解释这些URL渲染引擎,从而导致在MessageBox的阅读顺序,代表的呈现为从右到左(RTL)的。
当您使用系统模式消息框,表明该系统内存不足,字符串指向的lpText和lpCaption参数不应该从一个资源文件,因为采取的尝试加载资源可能会失败。
如果您创建一个消息框时出现一个对话框,目前,使用句柄作为hWnd参数对话框。在hWnd参数不能确定,如在一个对话框控件一个子窗口。
Windows 95/98/Me中:该系统可以支持最多16364窗口句柄。
Windows NT/2000/XP的:在MB_SERVICE_NOTIFICATION值的变化与Windows NT 4.0开始。 Windows NT 4.0提供落后的旧值映射到在这些URL执行新的价值为先前存在的服务的兼容性。此映射只完成了可执行文件的版本号早于4.0,如连接器设置。
要构建一个服务,它使用MB_SERVICE_NOTIFICATION并可以同时运行在微软Windows NT 3.x和Windows NT 4.0中,您可以执行下列操作之一。
在链接时,指定版本号低于4.0以下。
在链接时,指定版本4.0。在运行时,使用GetVersionEx函数来检查系统版本。然后,当运行在Windows NT 3.x中,使用MB_SERVICE_NOTIFICATION_NT3X和Windows NT 4.0上,使用MB_SERVICE_NOTIFICATION。
Windows 95/98/Me的:即使MessageBoxW存在,它是支持Unicode的由Microsoft层在Windows 95/98/Me系统,向更一致的行为,在所有的Windows操作系统。
例如
在下面的例子,应用程序显示一个消息框,提示一个动作错误情况后,用户有发生。该消息框显示消息的描述错误的情况,如何解决它。在MB_CANCELTRYCONTINUE风格指示这些URL提供了三个按钮,用户可以选择如何进行。样式设置的MB_DEFBUTTON2在这种情况下,对第二个按钮的消息框默认焦点,是再试一次按钮。
int DisplayResourceNAMessageBox()
{
int msgboxID = MessageBox(
NULL,
(LPCWSTR)L"Resource not available\\nDo you want to try again?",
(LPCWSTR)L"Account Details",
MB_ICONWARNING | MB_CANCELTRYCONTINUE | MB_DEFBUTTON2
);
switch (msgboxID)
{
case IDCANCEL:
// TODO: add code
break;
case IDTRYAGAIN:
// TODO: add code
break;
case IDCONTINUE:
// TODO: add code
break;
}
return msgboxID;
}
下图显示,从前面的代码示例的输出:
另一个消息框例如,见显示一个消息框。
功能信息
最低DLL版本 user32.dll
在Winuser.h中HeaderDeclared,头文件:winuser.h
import libraryUser32.lib
最低操作系统Windows 95,Windows NT 3.1
UnicodeImplemented为ANSI和Unicode版本。
参见
对话框概述,FlashWindow,MessageBeep,MessageBoxEx,MessageBoxIndirect,SetForegroundWindow
==英文原文==MessageBox Function
Displays a modal dialog box that contains a system icon, a set of buttons, and a brief application-specific message, such as status or error information. The message box returns an integer value that indicates which button the user clicked.
Syntax
int MessageBox( HWND hWnd,
LPCTSTR lpText,
LPCTSTR lpCaption,
UINT uType
);
Parameters
hWnd
[in] Handle to the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window.
lpText
[in] Pointer to a null-terminated string that contains the message to be displayed. If the string consists of more than one line, you can separate the lines using a carriage return and/or linefeed character between each line.
lpCaption
[in] Pointer to a null-terminated string that contains the dialog box title. If this parameter is NULL, the default title is Error.
uType
[in] Specifies the contents and behavior of the dialog box. This parameter can be a combination of flags from the following groups of flags.
To indicate the buttons displayed in the message box, specify one of the following values.
MB_ABORTRETRYIGNORE
The message box contains three push buttons: Abort, Retry, and Ignore.
MB_CANCELTRYCONTINUE
Microsoft Windows 2000/XP: The message box contains three push buttons: Cancel, Try Again, Continue. Use this message box type instead of MB_ABORTRETRYIGNORE.
MB_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.
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.
To display an icon in the message box, specify one of the following values.
MB_ICONEXCLAMATION
An exclamation-point icon appears in the message box.
MB_ICONWARNING
An exclamation-point icon appears in the message box.
MB_ICONINFORMATION
An icon consisting of a lowercase letter i in a circle appears in the message box.
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. 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.
MB_ICONSTOP
A stop-sign icon appears in the message box.
MB_ICONERROR
A stop-sign icon appears in the message box.
MB_ICONHAND
A stop-sign icon appears in the message box.
To indicate the default button, specify one of the following values.
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.
To indicate the modality of the dialog box, specify one of the following values.
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 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 pop-up 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 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.
MB_DEFAULT_DESKTOP_ONLY
Windows NT/2000/XP: Same as 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.
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, the system 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/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 that 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.
For information on security considerations in regard to using this flag, see Interactive Services . In particular, be aware that this flag can produce interactive content on a locked desktop and should therefore be used for only a very limited set of scenarios, such as resource exhaustion.
MB_SERVICE_NOTIFICATION_NT3X
Windows NT/2000/XP: This value corresponds to the value defined for MB_SERVICE_NOTIFICATION for Windows NT version 3.51.
For more information on the changes between Windows NT 3.51 and Windows NT 4.0, see Remarks.
Return Value
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.
IDABORTAbort button was selected.
IDCANCELCancel button was selected.
IDCONTINUEContinue button was selected.
IDIGNOREIgnore button was selected.
IDNONo button was selected.
IDOKOK button was selected.
IDRETRYRetry button was selected.
IDTRYAGAINTry Again button was selected.
IDYESYes button was selected.
Remarks
The following system icons can be used in a message box by setting the uType parameter to the corresponding flag value:
IconFlag values
MB_ICONHAND, MB_ICONSTOP, or MB_ICONERROR
MB_ICONQUESTION
MB_ICONEXCLAMATION or MB_ICONWARNING
MB_ICONASTERISK or MB_ICONINFORMATION
Adding two right-to-left marks (RLMs), represented by Unicode formatting character U+200F, in the beginning of a MessageBox display string is interpreted by the Win32 MessageBox rendering engine so as to cause the reading order of the MessageBox to be rendered as right-to-left (RTL).
When you use a system-modal message box to indicate that the system is low on memory, the strings pointed to by the lpText and lpCaption parameters should not be taken from a resource file because an attempt to load the resource may fail.
If you create a message box while a dialog box is present, use a handle to the dialog box as the hWnd parameter. The hWnd parameter should not identify a child window, such as a control in a dialog box.
Windows 95/98/Me: The system can support a maximum of 16,364 window handles.
Windows NT/2000/XP: The value of MB_SERVICE_NOTIFICATION changed starting with Windows NT 4.0. Windows NT 4.0 provides backward compatibility for preexisting services by mapping the old value to the new value in the implementation of MessageBox. This mapping is done only for executables that have a version number earlier than 4.0, as set by the linker.
To build a service that uses MB_SERVICE_NOTIFICATION and can run on both Microsoft Windows NT 3.x and Windows NT 4.0, you can do one of the following.
At link-time, specify a version number less than 4.0.
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.
Windows 95/98/Me: Even though MessageBoxW exists, it is supported by the Microsoft Layer for Unicode on Windows 95/98/Me Systems to give more consistent behavior across all Windows operating systems.
Example
In the following example, the application displays a message box that prompts the user for an action after an error condition has occurred. The message box displays the message that describes the error condition and how to resolve it. The MB_CANCELTRYCONTINUE style directs MessageBox to provide three buttons with which the user can choose how to proceed. The MB_DEFBUTTON2 style sets the default focus on the second button of the message box, in this case, the Try Again button.
int DisplayResourceNAMessageBox()
{
int msgboxID = MessageBox(
NULL,
(LPCWSTR)L"Resource not available\\nDo you want to try again?",
(LPCWSTR)L"Account Details",
MB_ICONWARNING | MB_CANCELTRYCONTINUE | MB_DEFBUTTON2
);
switch (msgboxID)
{
case IDCANCEL:
// TODO: add code
break;
case IDTRYAGAIN:
// TODO: add code
break;
case IDCONTINUE:
// TODO: add code
break;
}
return msgboxID;
}
The following image shows the output from the preceding code example:
For another message box example, see Displaying a Message Box .
Function Information
Minimum DLL Versionuser32.dll
HeaderDeclared in Winuser.h, include Windows.h
Import libraryUser32.lib
Minimum operating systemsWindows 95, Windows NT 3.1
UnicodeImplemented as ANSI and Unicode versions.
See Also
Dialog Boxes Overview , FlashWindow , MessageBeep , MessageBoxEx , MessageBoxIndirect , SetForegroundWindow
==原始网址==http://msdn.microsoft.com/en-us/library/ms645505(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 9:20:00