ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

5.返回值IDCANCEL和CommDlgExtendedError函数 -windows编程

2022-06-20 00:33:56  阅读:180  来源: 互联网

标签:box function CommDlgExtendedError windows CDERR failed common dialog IDCANCEL


 引言:今天看MicrosoftDoc关于CFileDialog的doModal函数返回值的部分,提到了实际上MFC提供了错误信息显示。       个人技术博客(文章整理+源码): https://zobolblog.github.io/LearnWinAPI/   1.用法:       CFileDialog::DoModal的返回值IDOK或IDCANCEL。如果返回IDCANCEL,请调用Windows CommdLGextenderror函数以确定是否发生错误。       CommDlgExtendedError函数可以返回任何常见对话框函数的常规错误代码。如果由于用户关闭或取消了对话框,公共对话框函数返回FALSE,则返回值为零。否则,返回值为非零错误代码。此外,还存在仅针对特定公用对话框返回的错误代码。所有这些错误代码都在Cderr中定义。h、 对于任何常用对话框函数,都可以返回以下常规错误代码。   2.错误类型:     CDERR_DIALOGFAILURE 0xFFFF:The dialog box could not be created. The common dialog box function's call to the DialogBox function failed. For example, this error occurs if the common dialog box call specifies an invalid window handle.     CDERR_FINDRESFAILURE 0x0006:The common dialog box function failed to find a specified resource.     CDERR_INITIALIZATION 0x0002:The common dialog box function failed during initialization. This error often occurs when sufficient memory is not available.     CDERR_LOADRESFAILURE 0x0007:The common dialog box function failed to load a specified resource.     CDERR_LOADSTRFAILURE 0x0005:The common dialog box function failed to load a specified string.     CDERR_LOCKRESFAILURE 0x0008:The common dialog box function failed to lock a specified resource.     CDERR_MEMALLOCFAILURE 0x0009:The common dialog box function was unable to allocate memory for internal structures.     CDERR_MEMLOCKFAILURE 0x000A:The common dialog box function was unable to lock the memory associated with a handle.     CDERR_NOHINSTANCE 0x0004:The ENABLETEMPLATE flag was set in the Flags member of the initialization structure for the corresponding common dialog box, but you failed to provide a corresponding instance handle.     CDERR_NOHOOK 0x000B: The ENABLEHOOK flag was set in the Flags member of the initialization structure for the corresponding common dialog box, but you failed to provide a pointer to a corresponding hook procedure.     CDERR_NOTEMPLATE 0x0003:The ENABLETEMPLATE flag was set in the Flags member of the initialization structure for the corresponding common dialog box, but you failed to provide a corresponding template.     CDERR_REGISTERMSGFAIL 0x000C:The RegisterWindowMessage function returned an error code when it was called by the common dialog box function.     CDERR_STRUCTSIZE 0x0001:The lStructSize member of the initialization structure for the corresponding common dialog box is invalid.       还有很多,可以看一下官方列表:https://docs.microsoft.com/en-us/windows/win32/api/commdlg/nf-commdlg-commdlgextendederror   3.相关网址:     https://docs.microsoft.com/en-us/cpp/mfc/reference/cfiledialog-class?view=msvc-170#domodal     https://docs.microsoft.com/en-us/windows/win32/api/commdlg/nf-commdlg-commdlgextendederror   4.个人理解:
    由于MFC是90年代编写出来的,所以局限于当时的计算机性能,很多设计都比较保守。比如错误信息没法像QT一样(不过qt也是91年发布的,好像)直接打印出来,而是不得不单独再出一个函数进行显示,而且只能显示一个16bit的数字,不能显示字符串。     此外,是多个Dialog共用一个错误提示区域,官方文档也写了“ the most recent error”,就是这个函数CommDlgExtendedError把一个App类的公共成员变量显示了出来。也就是说如果两个窗口的关闭时间挨的特别近,两个都错误了,前面一个的错误信息就被覆盖了。这个完全就是设计历史比较悠久,一个缺陷了。   源码:     
    CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,_T("All FILE|*.*|"),NULL,NULL,1);

    if (dlg.DoModal() != IDOK)
    {
        CommDlgExtendedError();
    }

 

标签:box,function,CommDlgExtendedError,windows,CDERR,failed,common,dialog,IDCANCEL
来源: https://www.cnblogs.com/zobol/p/16391909.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有