说明:向用户显示指定的消息。
使用MessageBox显示包含消息和一个或多个按钮的通用对话框。caption参数指定对话框的标题,并且是可选的。
MessageBox是Windows API MessageBox函数的封装,如http://msdn.microsoft.com/ms645505(v=vs.85.aspx)所述。
消息框的应用程序封装会自动提供Windows API函数所需的缺少的窗口句柄参数。
文本参数的值是消息,必要时可以超过255个字符。长消息自动包装在消息框中。
caption参数的值是显示在对话框标题栏中的标题。标题长度可以超过255个字符,但不能换行。长标题会产生一个宽消息框。
flags参数指定消息框上显示的按钮和行为(可能的返回值)。下表列出了可能的值。可以组合这些值以获得所需的效果。
示例:
procedure TForm1.Button1Click(Sender: TObject);
begin
with Application do
begin
NormalizeTopMosts;
MessageBox(0,'This should be on top.', 'Look', MB_OK); // [smbOK]
RestoreTopMosts;
end;
end;
Value | Meaning |
---|---|
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. |
如果内存不足,无法创建消息框,则MessageBox返回0。否则,它将返回以下值之一:
Value | Numeric Value | Meaning |
---|---|---|
IDOK |
1 |
The user chose the OK button. |
IDCANCEL |
2 |
The user chose the Cancel button. |
IDABORT |
3 |
The user chose the Abort button. |
IDRETRY |
4 |
The user chose the Retry button. |
IDIGNORE |
5 |
The user chose the Ignore button. |
IDYES |
6 |
The user chose the Yes button. |
IDNO |
7 |
The user chose the No button. |