Visual c++ 如何在属性页之间交换数据?

Visual c++ 如何在属性页之间交换数据?,visual-c++,mfc,Visual C++,Mfc,我有一个属性表,其中包含4个页面。在第二个页面中,我有一个列表控件,其中它被一些值枚举。在第三个页面中,我有一个listbox。无论listcontrol在第二个页面中被枚举的值是什么,都应该添加到第三个页面的listbox中。 //第二页listcontrol的DDX例程如下所示 void DoDataExchange(CDataExchange* pDX) { CPropertyPage::DoDataExchange(pDX); DDX_Control(pDX, IDC_LIS

我有一个属性表,其中包含4个页面。在第二个页面中,我有一个列表控件,其中它被一些值枚举。在第三个页面中,我有一个listbox。无论listcontrol在第二个页面中被枚举的值是什么,都应该添加到第三个页面的listbox中。 //第二页listcontrol的DDX例程如下所示

void DoDataExchange(CDataExchange* pDX)
{
   CPropertyPage::DoDataExchange(pDX);
   DDX_Control(pDX, IDC_LIST_MODEL, m_listCtrl);
}
void DoDataExchange(CDataExchange* pDX)
{
   CPropertyPage::DoDataExchange(pDX);
   DDX_Control(pDX, IDC_LIST_BOX, m_listBoxCtrl);
}
BOOL OnInitDialog()
{
  CPropertyPage::OnInitDialog();
  Updatedata(FALSE);
  m_ListBoxCtrl.AddString(m_szItemData);
  m_ListBoxCtrl.AddString(m_szItemData1);
  m_ListBoxCtrl.AddString(m_szItemData2);
  return TRUE;
}
//第三页lisbox的DDX例程如下所示

void DoDataExchange(CDataExchange* pDX)
{
   CPropertyPage::DoDataExchange(pDX);
   DDX_Control(pDX, IDC_LIST_MODEL, m_listCtrl);
}
void DoDataExchange(CDataExchange* pDX)
{
   CPropertyPage::DoDataExchange(pDX);
   DDX_Control(pDX, IDC_LIST_BOX, m_listBoxCtrl);
}
BOOL OnInitDialog()
{
  CPropertyPage::OnInitDialog();
  Updatedata(FALSE);
  m_ListBoxCtrl.AddString(m_szItemData);
  m_ListBoxCtrl.AddString(m_szItemData1);
  m_ListBoxCtrl.AddString(m_szItemData2);
  return TRUE;
}
在第二页的OnWizardNext()中,我添加了以下代码,将第二页的listcontrol值分配给第三页的成员变量

LRESULT OnWizardNext()

{
  UpdateData(TRUE);
  int nListItemCount = m_listCtrl.GetItemCount();
  m_str = m_listCtrl.GetItemText(0,1);
  m_str1 = m_listCtrl.GetItemText(0,2);
  m_str2 = m_listCtrl.GetItemText(0,3);
  //assigning the second page data member values to the third page member variables.
  CConfirmationView dlg;//third page class
  dlg.m_szItemData.Format(L"  %s",m_str);
  dlg.m_szItemData1.Format(L"  %s",m_str1);
  dlg.m_szItemData2.Format(L"  %s",m_str2);
  UpdateData(FALSE);
  return CPropertyPage::OnWizardNext();
}
在第三个页面OnInitDialog()中,我添加了这段代码,以将从第二个页面listcontrol检索到的值添加到第三个页面listbox,如下所示

void DoDataExchange(CDataExchange* pDX)
{
   CPropertyPage::DoDataExchange(pDX);
   DDX_Control(pDX, IDC_LIST_MODEL, m_listCtrl);
}
void DoDataExchange(CDataExchange* pDX)
{
   CPropertyPage::DoDataExchange(pDX);
   DDX_Control(pDX, IDC_LIST_BOX, m_listBoxCtrl);
}
BOOL OnInitDialog()
{
  CPropertyPage::OnInitDialog();
  Updatedata(FALSE);
  m_ListBoxCtrl.AddString(m_szItemData);
  m_ListBoxCtrl.AddString(m_szItemData1);
  m_ListBoxCtrl.AddString(m_szItemData2);
  return TRUE;
}
//从InitInstance()调用向导

我就是这样做的。我希望将listcontrol(第二页)的项数据添加到listbox(第三页)。
任何人都可以告诉我如何在页面之间交换数据。

CConfirmationView dlg//第三个页面类
将不起作用,您需要指向对话框创建时的实际实例的指针(通常在应用程序的
InitInstance()
方法中);您可以将指向对话框的指针作为成员变量存储在应用程序类中

// add member variable in myapp class (myapp.h)
public:
CThirdPage *m_pThirdPage;

第二页的
OnWizardNext()
将具有如下逻辑

//assigning the second page data member values to the third page member variables.
myapp *pApp = (myapp *) AfxGetApp();
pApp->m_pThirdPage->m_szItemData.Format(L"  %s",m_str);
pApp->m_pThirdPage->m_szItemData1.Format(L"  %s",m_str1);
pApp->m_pThirdPage->m_szItemData2.Format(L"  %s",m_str2);

通过构造函数将指向
cpropertysheet
的指针传递给每个
CPropertyPages
,这样您就可以访问父表中定义的所有其他页面,然后将这些页面声明为关注的其他页面的好友类,这样您就可以访问所需的成员并调用其
UpdateData()

我试着按照您建议的方式进行操作。然后我遇到了一个错误(Cbaseclass是未声明的基类)实际上,所有的页面都是从一个名为CbaseClass的基类派生的,而这个基类是从CpPropertyPage派生的。因此,它总是指示相同的错误,因为CbaseClass是CConfirmationView类的ConfirmationView.h文件中未声明的基类,光标正在头文件中移动到此位置。类CConfimationView:public CInstallerBase{//此处是位置,它指示错误。我甚至添加了头文件(检查了两次)您是否可以编辑问题并添加代码,显示如何调用向导以及从何处调用向导?请在我添加调用向导的代码的末尾查找代码中的更改。