• MFC:AfxMessageBox函数随记


    函数原型

    函数原型1

    int AfxMessageBox(
    LPCTSTR lpszText,
    UINT nType = MB_OK,
    UINT nIDHelp = 0
    );
    
    • 1
    • 2
    • 3
    • 4
    • 5

    lpszText:弹窗内容
    nType :弹窗类型和按钮类型进行或,比如询问框等

    函数原型2

    int AFXAPI AfxMessageBox(
    UINT nIDPrompt,
    UINT nType = MB_OK,
    UINT nIDHelp = (UINT)1
    );
    
    • 1
    • 2
    • 3
    • 4
    • 5

    nIDPrompt:为文本字符串ID

    函数说明

    1.AfxMessageBo是一个全局函数,不需要对应着一个窗口类,不能控制消息框标题,常用于调试程序时的内部数据输出或警告;
    2.MessageBox比较正式,常用在要提交的应用程序版本中,可以控制标题内容而不必采用含义不明的可执行文件名为标题

    弹窗按钮类型

    MB_ABORTRETRYIGNORE :Abort、Retry、Ignore按钮
    MB_OK :OK按钮
    MB_OKCANCEL :OK、Cancel按钮
    MB_RETRYCANCEL :Retry、Cancel按钮
    MB_YESNO :Yes、No按钮
    MB_YESNOCANCEL :Yes、No、Cancel按钮
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    图标风格

    MB_ICONINFORMATION :i图标,表示提示
    MB_ICONEXCLAMATION :惊叹号图标,表示警告
    MB_ICONSTOP :手形图标,表示警告或严重错误
    MB_ICONQUESTION :问号图标,表示疑问
    
    • 1
    • 2
    • 3
    • 4

    返回值

    IDABORT、IDCANCEL、IDIGNORE、IDNO、IDOK 、IDRETRY、IDYES
    
    • 1

    返回值说明

    Zero if there is not enough memory to display the message box; otherwise one of the following values is returned:
    IDABORT The Abort button was selected.
    IDCANCEL The Cancel button was selected.
    IDIGNORE The Ignore button was selected.
    IDNO The No button was selected.
    IDOK The OK button was selected.
    IDRETRY The Retry button was selected.
    IDYES The Yes button was selected.
    If a message box has a Cancel button, the IDCANCEL value will be returned if either the ESC key is pressed or the Cancel button is selected. If the message box has no Cancel button, pressing the ESC key has no effect

    函数原型1例子

    int AfxMessageBox(
    LPCTSTR lpszText,
    UINT nType = MB_OK,
    UINT nIDHelp = 0
    );
    
    • 1
    • 2
    • 3
    • 4
    • 5

    例子1

    AfxMessageBox(_T("加载失败"),MB_OK |MB_ICONEXCLAMATION );
    
    • 1

    在这里插入图片描述

    例子2

        int nRet =  AfxMessageBox(_T("加载失败"),MB_YESNO|MB_ICONQUESTION);
    	if(IDYES  == nRet){
    		AfxMessageBox(_T("是"),MB_ICONINFORMATION );
    	}else{
    		AfxMessageBox(_T("否"),MB_ICONINFORMATION );
    	}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    在这里插入图片描述

    例子3

    	int nRet =  AfxMessageBox(_T("加载失败"),MB_ABORTRETRYIGNORE );
    	if(IDABORT  == nRet ){
    		AfxMessageBox(_T("中止"),MB_ICONINFORMATION );
    	}
    	else if(IDRETRY == nRet){
    		AfxMessageBox(_T("重试"),MB_ICONINFORMATION );
    	}
    	else if(IDIGNORE == nRet){
    		AfxMessageBox(_T("忽略"),MB_ICONINFORMATION );
    	}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    在这里插入图片描述

    例子4

        int nRet =  AfxMessageBox(_T("加载失败"),MB_OKCANCEL|MB_ICONQUESTION  );
    	if(IDOK   == nRet ){
    		AfxMessageBox(_T("确定"),MB_ICONINFORMATION );
    	}
    	else if(IDCANCEL  == nRet){
    		AfxMessageBox(_T("取消"),MB_ICONINFORMATION );
    	}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    在这里插入图片描述

    例子5

    	int nRet =  AfxMessageBox(_T("加载失败"),MB_RETRYCANCEL |MB_ICONQUESTION  );
    	if(IDRETRY    == nRet ){
    		AfxMessageBox(_T("重试"),MB_ICONINFORMATION );
    	}
    	else if(IDCANCEL  == nRet){
    		AfxMessageBox(_T("取消"),MB_ICONINFORMATION );
    	}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    在这里插入图片描述

    例子6

        int nRet =  AfxMessageBox(_T("加载失败"),MB_YESNOCANCEL  |MB_ICONQUESTION   );
    	if(IDYES    == nRet ){
    		AfxMessageBox(_T("是"),MB_ICONINFORMATION );
    	}
    	if(IDNO     == nRet ){
    		AfxMessageBox(_T("否"),MB_ICONINFORMATION );
    	}
    	else if(IDCANCEL  == nRet){
    		AfxMessageBox(_T("取消"),MB_ICONINFORMATION );
    	}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    在这里插入图片描述

    函数原型2例子

    int AFXAPI AfxMessageBox(
    UINT nIDPrompt,
    UINT nType = MB_OK,
    UINT nIDHelp = (UINT)1
    );
    
    • 1
    • 2
    • 3
    • 4
    • 5

    这个函数里面的nIDPrompt可用string table里面的ID
    在这里插入图片描述

     AfxMessageBox(IDS_STRING102,MB_OK |MB_ICONEXCLAMATION );
    
    • 1

    在这里插入图片描述

  • 相关阅读:
    【js逆向实战】某讯漫画网站图片逆向
    MyBatis大数据量插入方案
    从零学习Linux操作系统 第三十二部分 ansible中剧本的应用
    vim的使用笔记
    IDEA快捷键记录
    Spring Security 自定义用户信息端点与多种登录方式共存
    Nginx开启Brotli
    Qt编程,事件过滤器、绘图
    Transformer【第五章】
    HarmonyOS 学习记录
  • 原文地址:https://blog.csdn.net/weixin_43333380/article/details/126806899