当前位置:网站首页>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 .
边栏推荐
- Bilinear upsampling and f.upsample in pytorch_ bilinear
- RSN:Learning to Exploit Long-term Relational Dependencies in Knowledge Graphs
- Golang multi graph generation gif
- 4. [WebGIS practice] software operation chapter - data import and processing
- pytorch中的双线性插值上采样(Bilinear Upsampling)、F.upsample_bilinear
- Leetcode:剑指 Offer 59 - I. 滑动窗口的最大值
- Appium自动化测试基础--补充:C/S架构和B/S架构说明
- Implement pow (x, n) function
- 详解Spark运行模式(local+standalone+yarn)
- Future of NTF and trends in 2022
猜你喜欢
![[small sample segmentation] interpretation of the paper: prior guided feature enrichment network for fee shot segmentation](/img/b3/887d3fb64acbf3702814d32e2e6414.png)
[small sample segmentation] interpretation of the paper: prior guided feature enrichment network for fee shot segmentation

pytorch中的双线性插值上采样(Bilinear Upsampling)、F.upsample_bilinear

Bilinear upsampling and f.upsample in pytorch_ bilinear

用小程序的技术优势发展产业互联网

【TA-霜狼_may-《百人计划》】2.2 模型与材质空间

详解Spark运行模式(local+standalone+yarn)

【TA-霜狼_may-《百人计划》】1.2.1 向量基础

【TA-霜狼_may-《百人计划》】2.3 常用函数介绍
![[小样本分割]论文解读Prior Guided Feature Enrichment Network for Few-Shot Segmentation](/img/b3/887d3fb64acbf3702814d32e2e6414.png)
[小样本分割]论文解读Prior Guided Feature Enrichment Network for Few-Shot Segmentation

Develop industrial Internet with the technical advantages of small programs
随机推荐
171. excel table column No
Quickly filter data such as clock in time and date: Excel filter to find whether a certain time point is within a certain time period
6. zigzag transformation
5. [WebGIS practice] software operation - service release and permission management
166. fractions to decimals
ASGNet论文和代码解读2
You cannot right-click F12 to view the source code solution on the web page
[深度学习]激活函数(Sigmoid等)、前向传播、反向传播和梯度优化;optimizer.zero_grad(), loss.backward(), optimizer.step()的作用及原理
187. 重复的DNA序列
409. longest palindrome
[reach out to Party welfare] developer reload system sequence
【TA-霜狼_may-《百人计划》】1.4 PC手机图形API介绍
208. implement trie (prefix tree)
409. 最长回文串
The method to measure the similarity of two vectors: cosine similarity, pytorch calculate cosine similarity: torch nn. CosineSimilarity(dim=1, eps=1e-08)
使用selenium自动化测试工具爬取高考相关院校专业招生分数线及排名情况
【TA-霜狼_may-《百人计划》】1.3纹理的秘密
[TA frost wolf \u may- hundred people plan] 2.3 introduction to common functions
jeecgboot输出日志,@Slf4j的使用方法
214. 最短回文串