Solved

CPropertySheet Data Update

Posted on 2003-11-03
7
645 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 53
no14 challenge 14 73
has77  challenge 9 98
"Black Box" Testing of Control System Software 2 97
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: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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