错误 运行 新创建的 MFC 项目

Error running a newly created MFC project

我在 Visual Studio 中创建了一个 MFC 项目并尝试 运行 它但是出现了如图所示的错误。

这是代码:

   #include "pch.h"    #include "framework.h"    #include "MFCApplication1.h"
   #include "ChildFrm.h"
   #ifdef _DEBUG    #define new DEBUG_NEW    #endif
   // CChildFrame
   IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWndEx)
   BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWndEx)
ON_COMMAND(ID_FILE_PRINT, &CChildFrame::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CChildFrame::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CChildFrame::OnFilePrintPreview)
ON_UPDATE_COMMAND_UI(ID_FILE_PRINT_PREVIEW,    &CChildFrame::OnUpdateFilePrintPreview) END_MESSAGE_MAP()
   // CChildFrame construction/destruction
   CChildFrame::CChildFrame() noexcept {    // TODO: add member    initialization code here }
   CChildFrame::~CChildFrame() { }

   BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs) {    // TODO:    Modify the Window class or styles here by modifying the CREATESTRUCT    cs  if( !CMDIChildWndEx::PreCreateWindow(cs) )      return FALSE;

cs.style = WS_CHILD | WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION |    WS_SYSMENU       | FWS_ADDTOTITLE | WS_THICKFRAME;

return TRUE; }
   // CChildFrame diagnostics
   #ifdef _DEBUG void CChildFrame::AssertValid() const {    CMDIChildWndEx::AssertValid(); }
   void CChildFrame::Dump(CDumpContext& dc) const {
CMDIChildWndEx::Dump(dc); }    #endif //_DEBUG
   // CChildFrame message handlers
   void CChildFrame::OnFilePrint() {    if    (m_dockManager.IsPrintPreviewValid())     {       PostMessage(WM_COMMAND,    AFX_ID_PREVIEW_PRINT);   } }
   void CChildFrame::OnFilePrintPreview() {     if    (m_dockManager.IsPrintPreviewValid())     {       PostMessage(WM_COMMAND,    AFX_ID_PREVIEW_CLOSE);  // force Print Preview mode closed   } }
   void CChildFrame::OnUpdateFilePrintPreview(CCmdUI* pCmdUI) {
pCmdUI->SetCheck(m_dockManager.IsPrintPreviewValid()); }

出现错误对话框 [无法启动程序 C:\Users\PC\Desktop\WindownsProject1\Debug\MFCApplication1.exe'。该系统找不到指定的文件。] [1]: https://i.stack.imgur.com/hvCiX.png [2]: https://i.stack.imgur.com/Kib9c.jpg

程序构建失败,因此未创建可执行文件。所以无法启动。

从您的屏幕截图看来,您没有安装 MFC 作为 visual studio 的一部分。所以您应该启动 visual studio 安装程序并安装 MFC 组件,然后重试。