不是CDialog的成员

error C2309: is not a member of CDialog

本文关键字:成员 CDialog 不是      更新时间:2023-10-16

我有一个结构:printchoosedgt .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,但我仍然得到相同的错误。谢谢你的帮助。

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

非常老的vc++,比如VC6,不关心正确的语法,生成不正确的消息映射