错误C2309:不是CDialog的成员

时间:2016-11-02 11:03:32

标签: c++ mfc header

我有结构:PrintChooseDlg.h

#ifndef PRINTCHOOSEDLG_H
#define PRINTCHOOSEDLG_H
#include <string>
#pragma once
#endif


class CPrintChooseDlg : public CDialog
{


public:
    int choosing;
    /*afx_msg void OnPrinter1();
    afx_msg void OnPrinter2();*/
CPrintChooseDlg(CWnd* pParent = NULL);
enum { IDD = IDD_PRINTBOX };


protected:
    virtual void DoDataExchange(CDataExchange* pDX);
    protected:
    //afx_msg void OnPrinter1();
    //afx_msg void OnPrinter2();
    virtual void OnPrinter1();
    virtual void OnPrinter2();
    DECLARE_MESSAGE_MAP()
};

和PrintChooseDlg.cpp

// PrintChoose.cpp : implementation file
//

#include "stdafx.h"
#include "Tungsten.h"
#include "PrintChooseDlg.h"

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

//IMPLEMENT_DYNAMIC(PrintChoose, CWnd)
CPrintChooseDlg::CPrintChooseDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CPrintChooseDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CChooseLabelDlg)
        // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
}


void CPrintChooseDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CChooseLabelDlg)
        // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPrintChooseDlg, CDialog)
    ON_BN_CLICKED(IDC_PRINTER1,OnPrinter1)
    ON_BN_CLICKED(IDC_PRINTER2,OnPrinter2)
END_MESSAGE_MAP()



// PrintChoose message handlers

void CPrintChooseDlg::OnPrinter1()
{
    choosing=0;
    CDialog::OnPrinter1();
}
void CPrintChooseDlg::OnPrinter2()
{
    choosing=1;
    CDialog::OnPrinter2();
}

在我运行的主文件中,我定义了以下标题:

#include "stdafx.h"
#include "Tungsten.h"
#include "TungstenDlg.h"
using namespace std;
#include<sstream>
#include <string>

问题是我总是遇到以下错误:错误C2039:'OnPrinter1':不是'CDialog'的成员 错误C2039:'OnPrinter2':不是'CDialog'的成员

我尝试的是在我的标题中添加#include <string>并确保不重复标题,并在我运行的主文件中定义Printer1和Pronter 2,但我仍然得到相同的错误。我感谢您的帮助。在此先感谢

1 个答案:

答案 0 :(得分:0)

要获取成员函数的地址,您需要使用&CPrintChooseDlg::OnPrinter1

真正老的VC ++,就像VC6一样,不关心正确的语法并生成错误的消息映射。