将变量从PropertyPage传递到MFC中的另一个变量 [英] Passing variables from PropertyPage to another in MFC

查看:104
本文介绍了将变量从PropertyPage传递到MFC中的另一个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...我正在设计MFC应用程序...在将变量从一个类传递到另一个类时遇到了麻烦..
我将清楚地说明我的问题...我有两个PropertyPages附加到PropertySheet

hey guys...I am designing an MFC application...I have a head-ache in passing variable from one class to another..
I will explian my problem clearly...I have two PropertyPages attached to a PropertySheet

BOOL CExtractorFinalUIApp::InitInstance()
{
	
	CMyPropertySheet  propSheet(L"Self Extractor") ;//PropertyClass

	CMyPropertyPage1 page1;
	CMyPropertyPage2 page2;
	
		
	propSheet.AddPage(&page1);
	propSheet.AddPage(&page2);
	
	m_pMainWnd = &propSheet;
	propSheet.SetWizardMode();
	int nResponse = propSheet.DoModal();
	if (nResponse == IDOK)
	{
		// TODO: Place code here to handle when the dialog is
		
	}
	else if (nResponse == IDCANCEL)
	{
		// TODO: Place code here to handle when the dialog is
		//  dismissed with Cancel
	}
	return FALSE;
}


如您在上面看到的,我已经将CPropertySheet设置为向导模式.因此,如果我单击下一步",它将移至下一页
我已附加,现在处理这笔交易...我在CMyPropertyPage1(这是PropertyPage1的类)中有一个变量"CString myapp"
并且此变量具有一些值,我希望将该值传递给第二个PropertyPage类(即)传递给CMyPropertyPage2(传递给其函数之一)...
我已经使用静态函数完成了此操作...但是我无法为我正在尝试2传递的所有变量编写函数...以及偏航
我相信那不是健康的编码方式...我听到了有关DDX的一些信息..我认为它仅适用于控制变量,例如
编辑控件...复选框,等等...是我可以通过您的任何一种协助解决此问题的方法吗?


As u can see above I have set the CPropertySheet in Wizard mode..so if I click "NEXT "..it moves to the next page
that I have attached and now heres the deal...I have a variable "CString myapp" in CMyPropertyPage1 (which is the class for PropertyPage1)
and this variable holds some value which I wish to pass to the 2nd PropertyPage Class ( i.e) to CMyPropertyPage2(to one of its function)...
I have done this using static functions...but I cannot write functions for all the variables that I am tryin 2 pass...and off-course
thats not the healthy way to code I beleive...I heard some thing about the DDX..i think it will work only for control variables such as
edit control...checkbox and such...is ther a way that I can fix this with any one of ur assistance?

推荐答案

您可以:
  1. CMyPropertySheet中添加公共获取/设置方法(您可以使用std::map来保存{name, value}对).
  2. 在创建页面时,将 sheet 的实例传递给页面本身.这样,每个页面都可以调用工作表的get/set方法.
  3. 例如
  1. Add public get/set methods to the CMyPropertySheet (you may use a std::map to hold {name, value} pairs).
  2. On creation of the pages, pass the instance of the sheet to the pages themselves. This way each page may call the get/set methods of the sheet.
  3. For instance
// header file of CMyPropertySheet
#include <map>
using namespace std;

CMyPropertySheet:public CPropertySheet
{
  //...
private:
  map< CString, int > m_ItemMap;
  //...
};


// source file of CMyPropertySheet
void CMyPropertySheet::setItem(CString key, int value)
{
  m_ItemMap.insert( make_pair(key, value) );
}
bool CMyPropertySheet::getItem(CString key, int & value)
{
  bool found = false;
  map< CString, int >::iterator it = m_ItemMap.find( key );
  if ( it != m_ItemMap.end() )
  {
    value = it->second;
    found = true;
  }
  return found;
}


// header file of CMyPropertyPage1
CMyPropertyPage1 : public CPropertyPage
{
private:
  CMyPropertySheet * m_pSheet;
public:
  CMyPropertyPage1(CMyPropertySheet * pSheet): m_pSheet(pSheet){}
}


和对CMyPropertyPage2的类似修改.

现在您可以这样做:


and a similar modification to CMyPropertyPage2.

Now you may do:

 CMyPropertySheet  propSheet(L"Self Extractor") ;//PropertyClass

 CMyPropertyPage1 page1(&propSheet);
 CMyPropertyPage2 page2(&propSheet);

 propSheet.AddPage(&page1);
 propSheet.AddPage(&page2);
// ..



并且每个属性页可以在需要时调用setItemgetItem,例如:



And each property page may call, when needed setItem or getItem, for instance:

CMyPropertyPage1::OnMyBtnDown()
{
  m_pSheet->setItem("FirstVar", 100);
}



:)



:)


这篇关于将变量从PropertyPage传递到MFC中的另一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆