Link to home
Start Free TrialLog in
Avatar of PMH4514
PMH4514

asked on

How to change to another Property Sheet and launch..

This might be blindingly easy, it's just new to me.

I have an application that is a single CPropertySheet containing several CPropertyPage instances.

void CScopePropSheet::AddControlPages()
{
      m_pSystemPage = new CSystemPage();
      m_pImagePage = new CImagePage();
        //... etc

       AddPage(m_pSystemPage );      
       AddPage(m_pImagePage );
       // ...etc
}

Say the user is working within m_pImagePage.  Clearly they could click the  System tab and change to that tab.  But I want to add a mechanism, whereby clicking a certain area in the image that is shown in Image Page, will force a transition to System Page, as well as call a method that m_pSystemPage implements.

(they could hit the System tab, and then click a button on the System page, but I need to essentially create  a "shortcut" from the Image Page that will change pages and call  initialization code in one click, under the hood)

All my click handling is in place, I just need to know how to make that page the active page (w/o the user having to hit the tab) and then execute a method within that page.

I hope that made sense :)

Thanks
-Paul
Avatar of AaronReams
AaronReams

Here is how you would go about it...  Just call a public member function of CSystemPage and then call SetActivePage in the property sheet.  Good luck -Aaron

// in class CSystemPage header file
public:
void DoSomething() { MessageBox("Do something");}

// in class CImagePage source file
void CImagePage::YouClickHandler(...)
{
((CScopePropSheet)GetParent())->m_pSystemPage->DoSomething();
((CScopePropSheet)GetParent())->SetActivePage(((CScopePropSheet)GetParent())->m_pSystemPage);
}



Avatar of PMH4514

ASKER

hmm.. I get these compile errors:

error C2440: 'type cast' : cannot convert from 'class CWnd *' to 'class CScopePropSheet'
error C2227: left of '->m_pScopePage' must point to class/struct/union
Avatar of PMH4514

ASKER

I can get basically the same thing to work, if I add a private member variable to my ImagePage of type CScopePropSheet, and then set it to "this" within the CScopePropSheeet after instantiating the ImagePage:

void CScopePropSheet::AddControlPages()
{
  m_pImagePage = new CImagePage();
  AddPage(m_pImagePage);
  m_pImagePage->SetPropSheetParent(this);  // accessor method I added to CImagePage to set private pointer to the prop sheet.

//..

}

then within my CImagePage

// your lines
//  ((CScopePropSheet)GetParent())->m_pSystemPage->DoSomething();
//  ((CScopePropSheet)GetParent())->SetActivePage(((CScopePropSheet)GetParent())->m_pSystemPage);            

// my lines, which call upon my private pointer which now points to my parent
m_pScopePropSheet->m_pSystemPage->DoSomething();
m_pScopePropSheet->SetActivePage(m_pScopePropSheet->m_pSystemPage);            


But while this is working,  I don't like that I had to explicitly store a pointer to the parent property sheet.. I must be doing something wrong.


thoughts?

Thanks

-Paul
ASKER CERTIFIED SOLUTION
Avatar of AaronReams
AaronReams

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
let me know if that works for ya.  cheers -Aaron
Avatar of PMH4514

ASKER

ahh.. perfect.. I should have seen that too.

thanks!
-paul