?
Solved

CPropertySheet Data Update

Posted on 2003-11-03
7
Medium Priority
?
651 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
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 1200 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

649 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