Solved

CPropertySheet Data Update

Posted on 2003-11-03
7
635 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

21 Experts available now in Live!

Get 1:1 Help Now