引言:今天看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 Dialog
Box 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();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。