CPropertySheet的双导数变得特别 [英] Double Derivation of CPropertySheet gets peculiar
问题描述
大家好,
我做了很多巫师,第二组与第一组非常相似,但有扩展功能.我想在两个向导(不同的属性表)中使用一些常见的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 thatGetParent
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, soGetParent
will return NULL. Accessing something through a NULL pointer will crash your application. Even if the wizard is a child of another windowGetParent
returns a HWND, which is not an instance ofCWizardSetup
. Trying to access a member ofCWizardSetup
through the window handle will return random data, rather than the required attribute.
This is much more complicated than you need anyway. Providedm_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屋!