|
我用的IDE是:Microsoft Visual Studio Community 2022 (64 位) - Current版本 17.2.3,在学习扩展文件选择对话框教学视频中(视频 地址:https://www.bilibili.com/video/BV1KJ411k7fX?p=109&spm_id_from=pageDriver),我按视频中的步骤,增加CFileDialogEx类:
但VC自动生成的代码(CFileDialogEx.h)如下:
- #pragma once
- #include <afxdlgs.h>
- class CFileDialogEx :public CFileDialog
- {
- };
复制代码 ,为什么类的内容是空的呢,这和视频不一致,我手动输入了类的内容如下:- #pragma once
- #include <afxdlgs.h>
- class CFileDialogEx :public CFileDialog
- {
- DECLARE_DYNAMIC(CFileDialogEx)
- public:
- CFileDialogEx(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
- LPCTSTR lpszDefExt = NULL,
- LPCTSTR lpszFileName = NULL,
- DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
- LPCTSTR lpszFilter = NULL,
- CWnd* pParentWnd = NULL);
- virtual ~CFileDialogEx();
- protected:
- DECLARE_MESSAGE_MAP()
- };
复制代码
CFileDialogEx.cpp内容如下:
- #include "pch.h"
- #include "MFCTest.h"
- #include "CFileDialogEx.h"
- IMPLEMENT_DYNAMIC(CFileDialogEx, CFileDialog)
- CFileDialogEx::CFileDialogEx(BOOL bOpenFileDialog, LPCTSTR lpszDefExt, LPCTSTR lpszFileName,
- DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd):
- CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd)
- {
-
- }
- CFileDialogEx::~CFileDialogEx(){}
复制代码
MFCTestDlg.cpp中相关代码如下:
- void CMFCTestDlg::OnBnClickedButton1()
- {
- // TODO: 在此添加控件通知处理程序代码
- CFileDialogEx fileDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT | OFN_ENABLETEMPLATE, _T("Text Files (*.txt)|*.txt|WinRar Files(*.rar)|*.rar|Data Files (*.xlc;*.xls)|*.xlc;*.xls|All Files (*.*)|*.*||"));
-
- if (fileDlg.DoModal() == IDOK) {
- POSITION pos = fileDlg.GetStartPosition();
- while (pos != NULL) {
- CString strPATH = fileDlg.GetNextPathName(pos);
- MessageBox(strPATH);
- }
- }
-
- }
复制代码
编译时报错如下:
- 错误 LNK2001 无法解析的外部符号 "protected: virtual struct AFX_MSGMAP const * __cdecl CFileDialogEx::GetMessageMap(void)const " (?GetMessageMap@CFileDialogEx@@MEBAPEBUAFX_MSGMAP@@XZ)
复制代码
请问错误原因是什么?如何解决,谢谢! |
-
上一篇: 求助,字符串编辑正常,控制台无输出。。。下一篇: 求助:OK不是对话框的成员
|