当前位置:网站首页>Usage of AfxMessageBox and MessageBox
Usage of AfxMessageBox and MessageBox
2022-07-01 03:47:00 【Three Belle Wenzi】
Catalog
1. Function definition prototype
3、 ... and 、 AfxMessageBox and MessageBox The difference between
One 、AfxMessageBox
AfxMessageBox Is a functional prototype , The feature is the executable file of the application , The function is the text displayed inside the message box ,AfxMessageBox and CWnd Class member functions are similar to , It's easy to use , the reason being that Afx Framework based functions .
about AfxMessageBox There are two definitions :
1. Function definition prototype
To define a :
int AfxMessageBox(
LPCTSTR lpszText,
UINT nType = MB_OK,
UINT nIDHelp = 0
);Definition 2 :
int AFXAPI AfxMessageBox(
UINT nIDPrompt,
UINT nType = MB_OK,
UINT nIDHelp = (UINT) –1
);2. Parameter Introduction
[1] Parameters 1
In the first form ,lpszText Indicates the contents of the pop-up window , The title of the pop-up window is application EXE Executable file name ( Such as Hello).
In the second form ,nIDPrompt Is a text string ID. When the function is called, it will be automatically selected from the string table according to ID Load string display .
[2] nType
nType It is a combination of button style and icon style displayed in the message box , May adopt |( or ) Operators combine various styles . Button styles include :
| MB_ABORTRETRYIGNORE | The message box displays Abort、Retry、Ignore Button |
| MB_OK | Show OK Button |
| MB_OKCANCEL | Show OK、Cancel Button |
| MB_RETRYCANCEL | Show Retry、Cancel Button |
| MB_YESNO | Show Yes、No Button |
| MB_YESNOCANCEL | Show Yes、No、Cancel Button |
Example 1:MB_ABORTRETRYIGNORE
int result = AfxMessageBox(L" Three Belle Wenzi ", MB_ABORTRETRYIGNORE); // suspend , retry , Ignore
Show(result); /* Click abort return 3, Click Retry return 4 Click ignore return 5 */Running results :

Example 2:MB_OK
int result = AfxMessageBox(L" Three Belle Wenzi ", MB_OK);
Show(result); /* Click ok return 1 */Running results :

Example 3:MB_OKCANCEL
int result = AfxMessageBox(L" Three Belle Wenzi ", MB_OKCANCEL);
Show(result); /* Click ok return 1, Click Cancel return 2 */Running results :

Example 4:MB_RETRYCANCEL
int result = AfxMessageBox(L" Three Belle Wenzi ", MB_RETRYCANCEL);
Show(result); /* Click Retry return 4, Click No return 7 Click Cancel return 2 */Running results :

Example 5:MB_YESNO
int result = AfxMessageBox(L" Three Belle Wenzi ", MB_YESNO);
Show(result); /* Click is return 6, Click No return 7 */Running results :

Example 6:MB_YESNOCANCEL
int result = AfxMessageBox(L" Three Belle Wenzi ", MB_YESNOCANCEL);
Show(result); /* Click is return 6, Click No return 7 Click Cancel return 2 */Running results :

[3] nIDHelp
Icon style
| MB_ICONINFORMATION | Display a i Icon , A hint |
| MB_ICONEXCLAMATION | Display an exclamation point , A warning |
| MB_ICONSTOP | Display the hand icon , Indicates a warning or serious error |
| MB_ICONQUESTION | Show the question mark icon , To express doubt |
Example 1:MB_ICONINFORMATION
AfxMessageBox(L" Three Belle Wenzi ", MB_ICONINFORMATION);Running results :

Example 2:MB_ICONEXCLAMATION
AfxMessageBox(L" Three Belle Wenzi ", MB_ICONEXCLAMATION);Running results :

Example 3:MB_ICONSTOP
AfxMessageBox(L" Three Belle Wenzi ", MB_ICONSTOP);Running results :

Example 4:MB_ICONQUESTION
AfxMessageBox(L" Three Belle Wenzi ", MB_ICONQUESTION);Running results :

matters needing attention :
If we just call :
AfxMessageBox(LPCTSTR lpszText);The system will default to :
AfxMessageBox(LPCTSTR lpszText,MB_OK|MB_ICONEXCLAMATION );3. Return value
The return value is 8 Kind of , If there's not enough memory , Then return to 0, Otherwise, one of the following values is returned , The corresponding buttons are clicked :IDABORT、IDCANCEL、IDIGNORE、IDNO、IDOK 、IDRETRY、IDYES. The values of various return values are shown in the following table :
| ID | Select results | Return value |
| IDOK | OK | 1 |
| IDCANCEL | CANCEL | 2 |
| IDABORT | ABORT | 3 |
| IDRETRY | RETRY | 4 |
| IDIGNORE | IGNORE | 5 |
| IDYES | YES | 6 |
| IDNO | NO | 7 |
Two 、MessageBox
MessageBox It means to display a modal dialog , It contains a system icon 、 A set of buttons and a short application specific message , Information such as status or error . An integer value is returned in the message box , This value indicates which button the user clicked .
1. Definition
To define a :
WINUSERAPI int WINAPI MessageBoxA(
HWND hWnd,
LPCSTR lpText,
LPCSTR lpCaption,
UINT uType);Definition 2 :
WINUSERAPI int WINAPI MessageBoxW(
HWND hWnd,
LPCWSTR lpText,
LPCWSTR lpCaption,
UINT uType);2. Parameter Introduction
[1] hWnd
This parameter represents the window owned by the message box . If NULL, Then the message box does not have a window .
[2] lpText
The contents of the message box . If used Unicode library , Turn the text into :
TEXT(/*sometext*/)[3] lpCaption
The title of the message box . If used Unicode library , Turn the text into :
TEXT(/*sometext*/) Example 1: MessageBox
MessageBox(TEXT(" Three Belle Wenzi "), TEXT("Serven Warning "), MB_TASKMODAL);Running results :

You can set your own title
[4] uType
Specify a set of bit flags that determine the content and behavior of the dialog box . This parameter can be a combination of flags in the following flag groups . Specify one of the following flags to display the buttons and icons in the message box .
Button parameters | meaning |
MB_OK | The default value is . There is a confirmation button inside . |
MB_YESNO | Yes or no in it . |
MB_ABORTRETRYIGNORE | Yes Abort( give up ),Retry( retry ) and Ignore( skip ) |
MB_YESNOCANCEL | The message box contains three buttons :Yes,No and Cancel |
MB_RETRYCANCEL | Yes Retry( retry ) and Cancel( Cancel ) |
MB_OKCANCEL | The message box contains two buttons :OK and Cancel |
Icon :
Parameters | meaning |
MB_ICONEXCLAMATION | An exclamation point appears in the message box |
MB_ICONWARNING | An exclamation point appears in the message box |
MB_ICONINFORMATION | Write small letters in a circle i The icon of the composition appears in the message box |
MB_ICONASTERISK | Write small letters in a circle i The icon of the composition appears in the message box |
MB_ICONQUESTION | A problem marker icon appears in the message box |
MB_ICONSTOP | A stop message icon appears in the message box |
MB_ICONERROR | A stop message icon appears in the message box |
MB_ICONHAND | A stop message icon appears in the message box |
form :
Parameters | meaning |
MB_APPLMODAL | stay hwnd Before continuing work in the window identified by the parameter , The user must respond to the message box . however , Users can move to windows of other threads and work in these windows . According to the hierarchical structure of the window in the application , The user moves to other windows in the thread . All child windows of the parent message box automatically expire , But pop ups are not like this . If neither MB_SYSTEMMODAL There is no designation MB_TASKMOOAL, be MB_APPLMODAL For the default . |
MB_SYSTEMMODAL | Except for the message box WB_EX_TOPMOST type ,MB_APPLMODAL and MB_SYSTEMMODAL equally . Use the system modal message box to change all kinds of users , Major damage errors require immediate attention ( for example , out of memory ). With those if not hwnd Contact window , This flag has no effect on the user's interaction with the window . |
MB_TASKMODAL | If parameters hwnd by NULL Words , Then, except that all windows belonging to the high-level of the current thread fail ,MB_TASKMODALL and MB_APPLMODAL equally . When the calling application or library does not have a window handle available , Use this sign . But you still need to block input to other windows of the calling thread , Instead of shelving other threads . |
other :
sign | meaning |
MB_DEFAULT_DESKTOP_ONLY | The current desktop receiving input must be a default desktop . otherwise , Function call failed . The default desktop is a desktop on which the user has recorded and on which the application will run in the future . |
MB_HELP | Put one Help The button is added to the message box . choice Help Button or press F1 Produce a Help event . |
MB_RIGHT | Text is right adjusted |
MB_RTLREADING | Use in Hebrew and Arabic Messages and uppercase text are displayed in the system from right to left . |
MB_SETFOREGROUND | The message box becomes the foreground window . Make a call for the message in the internal system SetForegroundWindow function . |
MB_TOPMOST | The message box uses WS_EX_TOPMOST Window type to create MB_SERVICE_NOTIFICATION. |
Return value :
| ID | Select results | Return value |
| IDOK | OK | 1 |
| IDCANCEL | CANCEL | 2 |
| IDABORT | ABORT | 3 |
| IDRETRY | RETRY | 4 |
| IDIGNORE | IGNORE | 5 |
| IDYES | YES | 6 |
| IDNO | NO | 7 |
Let's see how the source code defines the above :
// Button
#define MB_OK 0x00000000L
#define MB_OKCANCEL 0x00000001L
#define MB_ABORTRETRYIGNORE 0x00000002L
#define MB_YESNOCANCEL 0x00000003L
#define MB_YESNO 0x00000004L
#define MB_RETRYCANCEL 0x00000005L
// Icon
#define MB_ICONHAND 0x00000010L
#define MB_ICONQUESTION 0x00000020L
#define MB_ICONEXCLAMATION 0x00000030L
#define MB_ICONASTERISK 0x00000040L
#define MB_USERICON 0x00000080L
// Icon declaration
#define MB_ICONWARNINGMB_ICONEXCLAMATION
#define MB_ICONERRORMB_ICONHAND
#define MB_ICONINFORMATIONMB_ICONASTERISK
#define MB_ICONSTOPMB_ICONHAND
// Default button declaration
#define MB_DEFBUTTON1 0x00000000L
#define MB_DEFBUTTON2 0x00000100L
#define MB_DEFBUTTON3 0x00000200L
#if(WINVER>=0x0400)
#define MB_DEFBUTTON4 0x00000300L// If you support the fourth MessageBox Button words , Definition DEFButton4
#endif
// Dialog model definition
#define MB_APPLMODAL 0x00000000L
#define MB_SYSTEMMODAL 0x00001000L
#define MB_TASKMODAL 0x00002000L
#define MB_HELP 0x00004000L// Whether there is a help button
// Special statement
#define MB_NOFOCUS 0x00008000L
#define MB_SETFOREGROUND 0x00010000L
#define MB_DEFAULT_DESKTOP_ONLY 0x00020000L
#define MB_TOPMOST 0x00040000L
#define MB_RIGHT 0x00080000L
#define MB_RTLREADING 0x00100000L3、 ... and 、 AfxMessageBox and MessageBox The difference between
So much has been said , that AfxMessageBox and MessageBox What's the difference ?
1. Difference one
MessageBox() It's standard Win32 API function , You can use it directly ;AfxMessageBox yes MFC Global functions provided by the library , Provides a variety of overloaded forms , need MFC Framework support ( with afx Are framework based functions ). So in Win32 SDK Under the circumstances , Only use MessageBox( here MessageBox use Win 32 Prototype in ,hWnd Set to NULL); And in the MFC in , Both can be used ( here MessageBox use MFC Prototype in , stay CWnd Class or subclass ), But it's best to use it as much as possible AfxMessageBox, Here's why :
(1) stay MFC Can be used in MessageBox() All the places can be used AfxMessageBox(), That is to say, the latter can be used instead of the former ;
(2)AfxMessageBox This global function is the safest , It is also the most simple and convenient , Because it is a global function, it does not need a corresponding window class .
2. Difference two
MessageBox More formal , Often used in application versions to be submitted , You can control the content of the title , You don't have to use an ambiguous executable name as the title ( At this point ,MessageBox Than AfxMessageBox flexible , It can set any title , and AfxMessageBox You can't ).
AfxMessageBox Cannot control message box title , It is often used for internal data output or warning when debugging programs ( More often, it is used for debugging ).
3. Difference three
MessageBox stay Win 32 Prototype in , If the first parameter hWnd Set to NULL, Then the generated modeless dialog ;AfxMessageBox What is generated is a modal dialog , The program will not run until you confirm it , It will block your current thread , Unless your program is multithreaded , Otherwise, only wait for the modal dialog box to be confirmed .
边栏推荐
- jeecgboot输出日志,@Slf4j的使用方法
- C语言的sem_t变量类型
- [TA frost wolf \u may- hundred people plan] 2.4 traditional empirical lighting model
- 【TA-霜狼_may-《百人计划》】1.2.1 向量基础
- Sort linked list (merge sort)
- 【TA-霜狼_may-《百人计划》】2.2 模型与材质空间
- Appium fundamentals of automated testing - basic principles of appium
- 409. 最长回文串
- Pyramid Scene Parsing Network【PSPNet】论文阅读
- Use selenium automated test tool to climb the enrollment score line and ranking of colleges and universities related to the college entrance examination
猜你喜欢

Test function in pychram

衡量两个向量相似度的方法:余弦相似度、pytorch 求余弦相似度:torch.nn.CosineSimilarity(dim=1, eps=1e-08)
![[nine day training] content III of the problem solution of leetcode question brushing Report](/img/7e/1e76181e56ef7feb083f9662df71c7.jpg)
[nine day training] content III of the problem solution of leetcode question brushing Report

【TA-霜狼_may-《百人计划》】2.1 色彩空间

Unexpected token o in JSON at position 1, JSON parsing problem

小程序容器技术与物联网IoT的结合点

Leetcode 128 longest continuous sequence (hash set)

TEC: Knowledge Graph Embedding with Triple Context

The difference between MFC for static libraries and MFC for shared libraries

【TA-霜狼_may-《百人计划》】2.4 传统经验光照模型
随机推荐
Ouc2021 autumn - Software Engineering - end of term (recall version)
[EI conference] the Third International Conference on nanomaterials and nanotechnology in 2022 (nanomt 2022)
【EI检索】2022年第六届材料工程与先进制造技术国际会议(MEAMT 2022)重要信息会议网址:www.meamt.org会议时间:2022年9月23-25日召开地点:中国南京截稿时间:2
165. 比较版本号
idea插件备份表
Complete knapsack problem
Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C
在 C 中声明函数之前调用函数会发生什么?
4. [WebGIS practice] software operation chapter - data import and processing
盘点华为云GaussDB(for Redis)六大秒级能力
5. [WebGIS practice] software operation - service release and permission management
【TA-霜狼_may-《百人計劃》】1.2.1 向量基礎
RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
Blueprism registration, download and install -rpa Chapter 1
Pytorch training deep learning network settings CUDA specified GPU visible
171. excel table column No
How do I use Google Chrome 11's Upload Folder feature in my own code?
242. 有效的字母异位词
8. string conversion integer (ATOI)
The method to measure the similarity of two vectors: cosine similarity, pytorch calculate cosine similarity: torch nn. CosineSimilarity(dim=1, eps=1e-08)