Solved

CPropertySheet Data Update

Posted on 2003-11-03
7
637 Views
Last Modified: 2013-11-20
When a user presses OK on my property sheet...I need all the pages to update thier members...I cant call update data after DoModal...so how can I update all the pages data members before the window closes. Is there a way to override OnOK for the sheet???
0
Comment
Question by:SGyves
7 Comments
 
LVL 16

Expert Comment

by:_nn_
ID: 9675263
FWIW, I've never needed to specify something for that. I usually have

CSomeObj::OnSomeEvent()
{
    // CFirstPage is a descendant of CPropertyPage
    CFirstPage page1;
    // I've defined page1 in the ClassWizard (VC++6)
    page1.m_someField = someValue;

    // same here
    CSecondPage page2;
    page2.m_someOtherField = someOtherValue;

    CPropertySheet dlg(ID_SOME_DLG);
    dlg.AddPage(&page1);
    dlg.AddPage(&page2);

    if (dlg.DoModal()==IDOK) {
        // here I can read the variables, for instance
        someValue = page1.m_someField;
    }
}

And I don't even need to use a special sheet, the basic one is enough. And the members of the property pages are all updated as expected.

HTH
0
 
LVL 16

Expert Comment

by:_nn_
ID: 9675269
Sorry, I meant

    // I've defined the m_someField variable in the ClassWizard (VC++6)
0
 

Author Comment

by:SGyves
ID: 9675928
Yeah....I had a different problem i guess......this was okay.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9676052
Map all CpropertyPage's OnOK, when clicking on CpropertySheet's OK, his will call all CPropertyPage::OnOk from CPropertSheet::OnOK. hope this helps

Rosh :)
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9676078
Some tips and tricks to change the default look&feel and behavior of CPropertySheet class  
http://www.codeproject.com/property/hacking_the_cpropertyshee.asp - Hacking the CPropertySheet

Rosh :)
0
 

Expert Comment

by:himch
ID: 9676479
Hi

You can write your update code on the OnOK() on every property page. All those pages, which have been changed/accessed call their OnOK() when you press OK of the property sheet.
This should solve the problem.

Himanshu
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 300 total points
ID: 9677324
My technique is a little bit uniusual, but it has served me well.

I derive an object from CPropertySheet and I add a few functions
      LoadPages()
and
     SavePages()

Its .H file has a bunch of lines like this:
    CDlgPgMain       m_cPgMain;
    CDlgPgOptions   m_cPgOptions;
    CDlgPgLogging   m_cPgLogging;

so my LoadPages() starts out like this

      AddPage( &m_cPgMain );
      AddPage( &m_cPgOptions );
      AddPage( &m_cPgLogging );
      //------------------------------------------------------------ Load Up Main
      m_cPgMain.m_sEdit1="intital value";
      m_cPgMain.m_sEdit2= ... some value from the registry/Profile...
      //------------------------------------------------------------ Load Up Options
      m_cPgOptions.m_Edit1="intital value";
      ... etc...

And my SavePages() has a similar sequence, but in reverse:

      //------------------------------------------------------------ Save Main
      gSavedValue= m_cPgMain.m_sEdit1;
      PrgPrefs.sSomeOption- cPgMain.m_Edit2;
      //------------------------------------------------------------ Save Options
      WriteToDatabase( "yadaYada", m_cPgOptions.m_Edit1 );
      ... etc...

=-=-=-=-=-=-=-=-=-=-=-
One value of this technique is that all of the data is assigned and checked in one place... you don't have hunt down each CPropertyPage-derived object.

I (sometimes)  have a
      CanSave()
function that checks all of the data (also with a parallel set of line-items in the code).  If something is no good (some combination of conflicting values that the individula pages can't avoid easily, etc), then CanSave() fails.  It pops up a message box, and then activates the correct page.

In my CProprtySheet, I intercept OK and do not let the OK command finish if CanSave() fails.   Here is how I do that...

//------------------------------------------------------------
BOOL CDlgSheetABC::OnCommand(WPARAM wParam, LPARAM lParam)
{
      if ( wParam == IDOK ) {
            CPropertyPage* pPg= GetActivePage();
            pPg->UpdateData();
            if ( !CanSave() ) {
                  return( TRUE );  // yes, done processing (do nothing)
            }
      }
      return CPropertySheet::OnCommand(wParam, lParam);
}

And to start the whole thing...

      CDlgSheetABC cSheet( "Info", NULL, 0 /*iSelectPage*/ );
      cSheet.LoadPages();
      int iRet;
      while( TRUE ) {   // exit via break
            iRet= cSheet.DoModal();  //----------------- Edit the data
            if ( iRet != IDOK ) {
                  break;
            }
            if ( cSheet.SavePages() ) { // FALSE only on oddbal error or user cancel
                  break;
            }
      }
      return( iRet == IDOK );
}
=-=-=-=-=-=-=-=-
This technique has served me well.

-- Dan
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now