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.\nDo 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.\nDo 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()的參數:

第一個,不太理解。

第二個,指定要顯示的文本信息。

第三個,指定消息框的標題。

第四個,指定圖標,及按鍵等等。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM