C++ MessageBox()

关于MessageBox function,参考:https://msdn.microsoft.com/en-us/library/ms645505(VS.85).aspx

更多示例,参考Using Dialog Boxeshttps://msdn.microsoft.com/en-us/library/ms644996(v=vs.85).aspx#message_box

IDE: Code::Blocks 16.01

操作系统:Windows 7 x64

 1 #include <windows.h>
 2 #include <tchar.h>
 3 
 4 /* In the following example, the application displays a message box
 5    that prompts the user for an action after an error condition has occurred.
 6    The message box displays the message that describes the error condition
 7    and how to resolve it.
 8    The MB_YESNO style directs MessageBox to provide two buttons
 9    with which the user can choose how to proceed : */
10 int DisplayConfirmSaveAsMessageBox()
11 {
12     int msgboxID = MessageBox(
13         NULL,
14         "temp.txt already exists.
Do you want to replace it?",
15         "Confirm Save As",
16         MB_ICONEXCLAMATION | MB_YESNO
17     );
18 
19     if (msgboxID == IDYES)
20     {
21         // TODO: add code
22     }
23 
24     return msgboxID;
25 }
26 
27 int _cdecl _tmain()
28 {
29     DisplayConfirmSaveAsMessageBox();
30 
31     return 0;
32 }

在Code::Blocks 16.01中的运行结果:

IDE: Microsoft Visual Studio Community 2017 15.5.2

操作系统:Windows 7 x64

 1 #include "stdafx.h"
 2 
 3 #include <windows.h>
 4 
 5 /* In the following example, the application displays a message box 
 6    that prompts the user for an action after an error condition has occurred.
 7    The message box displays the message that describes the error condition 
 8    and how to resolve it.
 9    The MB_YESNO style directs MessageBox to provide two buttons 
10    with which the user can choose how to proceed : */
11 int DisplayConfirmSaveAsMessageBox()
12 {
13     int msgboxID = MessageBox(
14         NULL,
15         L"temp.txt already exists.
Do you want to replace it?",
16         L"Confirm Save As",
17         MB_ICONEXCLAMATION | MB_YESNO
18     );
19 
20     if (msgboxID == IDYES)
21     {
22         // TODO: add code
23     }
24 
25     return msgboxID;
26 }
27 
28 int _cdecl _tmain()
29 {
30     DisplayConfirmSaveAsMessageBox();
31 
32     return 0;
33 }

在Microsoft Visual Studio Community 2017 15.5.2中的运行结果:


 关于MessageBox()的参数:

第一个,不太理解。

第二个,指定要显示的文本信息。

第三个,指定消息框的标题。

第四个,指定图标,及按键等等。

原文地址:https://www.cnblogs.com/Satu/p/8214133.html