错误LNK2005:"已在SkinHeaderCtrl.obj"

时间:2016-01-13 21:03:50

标签: c++ lnk2005

我收到此错误"错误2错误LNK2005:" public:virtual __thiscall CMemDC :: ~CMemDC(void)" (?? 1CMemDC @@ UAE @XZ)已在SkinHeaderCtrl.obj中定义C:\ Users \ anthonyd \ Desktop \ ASPX \ STP \ nafxcwd.lib(afxglobals.obj)STP "

我已阅读了许多类似的问题,但找不到合适的问题。有人可以帮忙吗?

   // SkinHeaderCtrl.cpp : implementation file
//

#include "stdafx.h"
#include "STP.h"
#include "SkinHeaderCtrl.h"
#include "memdc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define BACKGROUND RGB(218,218,218)// was 218,218,218
#define HEIGHT 16
/////////////////////////////////////////////////////////////////////////////
// CSkinHeaderCtrl

CSkinHeaderCtrl::CSkinHeaderCtrl()
{
}

CSkinHeaderCtrl::~CSkinHeaderCtrl()
{
}


BEGIN_MESSAGE_MAP(CSkinHeaderCtrl, CHeaderCtrl)
    //{{AFX_MSG_MAP(CSkinHeaderCtrl)
    ON_WM_PAINT()
    ON_WM_ERASEBKGND()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSkinHeaderCtrl message handlers

void CSkinHeaderCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{

}

void CSkinHeaderCtrl::OnPaint() 
{
    CPaintDC dc(this); // device context for painting

    CRect rect, rectItem, clientRect;
    GetClientRect(&rect);
    GetClientRect(&clientRect);
    CMemDC memDC(&dc, rect);
    CDC bitmapDC;
    bitmapDC.CreateCompatibleDC(&dc);

//  memDC.FillSolidRect(&rect, RGB(76,85,118));
    memDC.FillSolidRect(&rect, BACKGROUND);

    CBitmap bitmapSpan;
    bitmapSpan.LoadBitmap(IDB_COLUMNHEADER_SPAN);
    CBitmap* pOldBitmapSpan = bitmapDC.SelectObject(&bitmapSpan);

//  memDC.StretchBlt(rect.left+2, 0, rect.Width(), 12, &bitmapDC, 0, 0, 1, 12, SRCCOPY);
    memDC.StretchBlt(rect.left+2, 0, rect.Width(), HEIGHT, &bitmapDC, 0, 0, 1, 12, SRCCOPY);

    bitmapDC.SelectObject(pOldBitmapSpan);
    bitmapSpan.DeleteObject();

    int nItems = GetItemCount();

    CBitmap bitmap;
    CBitmap bitmap2;
    CBitmap bitmap3;

这是skinheaderctrl.h

#if !defined(AFX_SKINHEADERCTRL_H__8B0847B1_B4E6_4372_A62D_038582FFEA5C__INCLUDED_)
#define AFX_SKINHEADERCTRL_H__8B0847B1_B4E6_4372_A62D_038582FFEA5C__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// SkinHeaderCtrl.h : header file
//


/////////////////////////////////////////////////////////////////////////////
// CSkinHeaderCtrl window

class CSkinHeaderCtrl : public CHeaderCtrl
{
// Construction
public:
    CSkinHeaderCtrl();

// Attributes
public:

// Operations
public:

// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CSkinHeaderCtrl)
    //}}AFX_VIRTUAL

// Implementation
public:
    virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
    virtual ~CSkinHeaderCtrl();

    // Generated message map functions
protected:
    //{{AFX_MSG(CSkinHeaderCtrl)
    afx_msg void OnPaint();
    afx_msg BOOL OnEraseBkgnd(CDC* pDC);
    //}}AFX_MSG

    DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_SKINHEADERCTRL_H__8B0847B1_B4E6_4372_A62D_038582FFEA5C__INCLUDED_)

更新

在skinheaderctrl.cpp上我有一个#include" memdc.h"我想将其更新为CMemDC吗?

1 个答案:

答案 0 :(得分:2)

CMemDC是MFC中的内部帮助器类(请参阅Internal Classes)。您显然定义了自己的CMemDC类,结果是链接器看到两个具有相同名称的析构函数。您必须将您的类重命名为其他名称或将其放在名称空间中以避免冲突。