简体   繁体   English

运行新创建的 MFC 项目时出错

[英]Error running a newly created MFC project

I created an MFC project in Visual Studio and tried to run it but it got the error as shown in the picture.我在 Visual Studio 中创建了一个 MFC 项目并尝试运行它,但出现如图所示的错误。

this is the code:这是代码:

   #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()); }

An error dialog appears [ Unable to start program C:\Users\PC\Desktop\WindownsProject1\Debug\MFCApplication1.exe'.出现错误对话框 [无法启动程序 C:\Users\PC\Desktop\WindownsProject1\Debug\MFCApplication1.exe'。 The system cannot find the file specified.] [1]: https://i.stack.imgur.com/hvCiX.png [2]: https://i.stack.imgur.com/Kib9c.jpg系统找不到指定的文件。] [1]: https://i.stack.imgur.com/hvCiX.png [2]: https://i.stack.imgur.com/Kib9c.jpg

The program fails to build, so the executable is not created.该程序无法构建,因此未创建可执行文件。 That's why it can't be started.这就是它无法启动的原因。

From your screenshots it appears that you don't have MFC installed as part of visual studio.从您的屏幕截图中,您似乎没有安装 MFC 作为 Visual Studio 的一部分。 So you should launch visual studio installer and install the MFC component, then try again.因此,您应该启动 Visual Studio 安装程序并安装 MFC 组件,然后重试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM