CPropertySheet的双导数变得特别 [英] Double Derivation of CPropertySheet gets peculiar

查看:86
本文介绍了CPropertySheet的双导数变得特别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我做了很多巫师,第二组与第一组非常相似,但有扩展功能.我想在两个向导(不同的属性表)中使用一些常见的CPropertyPages.

这个工作正常,所以我想也许我可以从我的第一个CPropertySheet中获得它!

第一个向导:-

Hi guys,

I have made a number of Wizards, the second set was very similar to the first but with extensions. I wanted to use some of the common CPropertyPages with both Wizards (different property sheets).

This worked OK so I thought maybe I could derive my second CPropertySheet from my first!

First Wizard:-

class CWizardSheet_ONE : public CPropertySheet
{
        DECLARE_DYNAMIC(CWizardsheet_ONE)
   public:
        CString m_csUsername;
...




第二个向导:-




Second Wizard:-

class CWizardSheet_TWO : public CWizardSheet_ONE ) //CPropertySheet
{
        DECLARE_DYNAMIC(CWizardSheet_TWO)
...



当我尝试使用CPropertySheet的第一个派生实例访问数据时,一切似乎都工作良好.



It all seemed to work well when I tried accessing data using an instance of the first derivation of CPropertySheet.

BOOL CSetupWizPage02::OnKillActive()
{
    UpdateData( TRUE );
    CWizardSheet_ONE *ptParent  = (CWizardSheet_ONE *)this->GetParent();
    ptParent->m_csUsername   = m_csUsername;



交换到下一页时,我想更新CWizardSheet_ONE变量.

我以为我可以使用CPropertyPage中的 GetParent()返回的指针来访问这些继承的变量-当CWizardSheet_ONE使用Page时,下面的代码起作用了.



I wanted to update a CWizardSheet_ONE variable when swapping to the next page.

I thought I could access these inherited variables by using the pointer returned by GetParent() in my CPropertyPage - the code below worked when the the Page was used by the CWizardSheet_ONE ..

BOOL CSetupWizPage02::OnKillActive()
{
	UpdateData( TRUE );
	CWizardSheet_ONE *ptParent	= (CWizardSheet_ONE *)this->GetParent();

	ptParent->m_csUsername	= m_csUsername;



但是,当我在CPropertySheet_TWO中使用以上页面时,GetParent()返回的指针并不指向CPropertSheet_TWO的基础-好像CPropertySheet继承已得到处理. 任何建议都将引起您的兴趣.

干杯!



But when I used the above page in CPropertySheet_TWO, the pointer returned by GetParent() was not to the base of CPropertSheet_TWO - it appears as though CPropertySheet inheritance is handled.
Any suggestions would be of interest.

Cheers!

推荐答案

问题是GetParent在继承层次结构中没有获取父类,而是在窗口层次结构中获取了父窗口.我怀疑该向导不是任何其他窗口的子级,因此GetParent将返回NULL.通过NULL指针访问某些内容会使您的应用程序崩溃.即使向导是另一个窗口的子代,GetParent也会返回HWND,它不是CWizardSetup的实例.尝试通过窗口句柄访问CWizardSetup的成员将返回随机数据,而不是必需的属性.

无论如何,这比您需要的要复杂得多.如果m_rtLocalStreamAccount是受保护的或公开的(最好是前者),那么您可以直接使用它,例如

The problem is that GetParent doesn''t get the parent class in the inheritance hierarchy, it gets the parent window in the window hierarchy. I suspect that the wizard is not a child of any other window, so GetParent will return NULL. Accessing something through a NULL pointer will crash your application. Even if the wizard is a child of another window GetParent returns a HWND, which is not an instance of CWizardSetup. Trying to access a member of CWizardSetup through the window handle will return random data, rather than the required attribute.

This is much more complicated than you need anyway. Provided m_rtLocalStreamAccount is either protected or public (preferably the former), then you just use it directly, e.g.

class CWizardSetup : public CPropertySheet
{
...

protected:
  StreamAccount  m_rtLocalSTreamAccount;
};

class CWizardRpcSetup : public CWizardSetup
{

  void MyFunction()
  {
     DoSomethingWithTheLocalStream(m_rtLocalSTreamAccount);
  }

};



如果确实愿意,可以使用this->m_rtLocalSTreamAccount,但这是不必要的.



You could use this->m_rtLocalSTreamAccount if you really wanted to, but this is unnecessary.


这篇关于CPropertySheet的双导数变得特别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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