简体   繁体   中英

MFC project has linking error on Visual Studio 2013?

When I tried to add a toolbar to my mfc project in Visual studio 2013, the following errors occurred. Has anyone worked on this? How can I fix the errors?

[ mfc project in visual studio 2013][1]

  [1]: https://i.stack.imgur.com/2LAab.png
 **The source code MFCModalOynaDlg.h is as follow:**
#pragma once

class CMFCModalOynaDlg : public CDialogEx
{
public:
    CMFCModalOynaDlg(CWnd* pParent = NULL); 

    enum { IDD = IDD_MFCMODALOYNA_DIALOG }; 

    protected:
    virtual void DoDataExchange(CDataExchange* pDX);

protected:
    HICON m_hIcon;
    CToolBar m_wndToolBar;
    BOOL butD;

    virtual BOOL OnInitDialog();
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    DECLARE_MESSAGE_MAP()
public:
      afx_msg void OnBnClickedOk();
};

The source code MFCModalOynaDlg.cpp is as follow:

 #include "stdafx.h"
    #include "MFCModalOyna.h"
    #include "MFCModalOynaDlg.h"
    #include "afxdialogex.h"
    #include "windows.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


CMFCModalOynaDlg::CMFCModalOynaDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CMFCModalOynaDlg::IDD, pParent)
{
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MYICON1);
}

void CMFCModalOynaDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CMFCModalOynaDlg, CDialogEx)
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
END_MESSAGE_MAP()

BOOL CMFCModalOynaDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();

    SetIcon(m_hIcon, TRUE);
    SetIcon(m_hIcon, FALSE);

    if (!m_wndToolBar.Create(this)|| !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1)) 
    {
        TRACE0("Failed to Create Dialog Toolbar\n");
    EndDialog(IDCANCEL);
}
butD = TRUE;
CRect rcClientOld;
CRect rcClientNew; 

GetClientRect(rcClientOld);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, rcClientNew);

CPoint ptOffset(rcClientNew.left - rcClientOld.left, rcClientNew.top - rcClientOld.top);

CRect rcChild;
CWnd* pwndChild = GetWindow(GW_CHILD); 

while (pwndChild) 
{
pwndChild->GetWindowRect(rcChild); 
ScreenToClient(rcChild);

rcChild.OffsetRect(ptOffset);
pwndChild->MoveWindow(rcChild, FALSE); 
pwndChild = pwndChild->GetNextWindow();
      }

      CRect rcWindow;
      GetWindowRect(rcWindow);

      rcWindow.right += rcClientOld.Width() - rcClientNew.Width();

      rcWindow.bottom += rcClientOld.Height() - rcClientNew.Height();
      MoveWindow(rcWindow, FALSE);

      RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);

    return TRUE;
}

Error 1 error LNK2001: unresolved external symbol "protected: void thiscall CMFCModalOynaDlg::OnPaint(void)" (?OnPaint@CMFCModalOynaDlg@@IAEXXZ) D:\VSprogram\MFCModalOyna\MFCModalOyna\MFCModalOynaDlg.obj MFCModalOyna Error 2 error LNK2001: unresolved external symbol "protected: struct HICON * thiscall CMFCModalOynaDlg::OnQueryDragIcon(void)" (?OnQueryDragIcon@CMFCModalOynaDlg@@IAEPAUHICON @@XZ) D:\VSprogram\MFCModalOyna\MFCModalOyna\MFCModalOynaDlg.obj MFCModalOyna

Error 3 error LNK1120: 2 unresolved externals D:\VSprogram\MFCModalOyna\Debug\MFCModalOyna.exe 1 1 MFCModalOyna

    [When I added a toolbar to my mfc project in visual studio 2013, the following errors occur. ][2]

 [2]: https://i.stack.imgur.com/qwgfi.png

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