简体   繁体   中英

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.

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'. The system cannot find the file specified.] [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. So you should launch visual studio installer and install the MFC component, then try again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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