CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 32

Thread: Design issue

  1. #16
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Design issue

    Here's the code. See the PropPageDocument.zip attachment in my reply about half way down the page.

  2. #17
    Join Date
    Oct 2006
    Posts
    128

    Re: Design issue

    I appreciate your suggestion Arjay. As Mike had suggested earlier, i do realise that by making a dll dialog and nesting it i am complicating things. Especially i need to collect the values of other controls for displaying the report and getting it from dll could get complicated

    Looking at your example, ....
    I was wondering what if i create property sheet with controls needed for different report type(the first combo box) and display which ever property sheet when the user changes the combobox value, is it possible? So instead of refreshing the same dialog, display the appropriate property sheet for that combobox selection, is it a good idea? will the property sheet work only on next button? I have never worked on Property sheet, so that's why this question.
    Last edited by rachelason; June 18th, 2008 at 02:59 AM. Reason: edit

  3. #18
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Design issue

    Quote Originally Posted by rachelason
    I was wondering what if i create property sheet with controls needed for different report type(the first combo box) and display which ever property sheet when the user changes the combobox value, is it possible? So instead of refreshing the same dialog, display the appropriate property sheet for that combobox selection, is it a good idea? will the property sheet work only on next button? I have never worked on Property sheet, so that's why this question.
    Sure it will work. Understand that there is only one CPropertySheet derived class, so you would be actually changing pages. From any page, you can get the pointer to the property sheet and call the SetActivePage method to move from page to page. In other words, when the user changes a combobox selection on page 1, you set up an OnSelectChanged handler and then call SetActivePage to take you to Page2, page3, or whatever.

  4. #19
    Join Date
    Oct 2006
    Posts
    128

    Re: Design issue

    Yes, that's what exactly i want to do.
    I created two pages, with controls needed. Added the content of the combobox1, then created an event to that. What i am not sure is, while creating variables for the control, will it reside in the individual class or in the sheet? If in the individual class , how would the sheet know which one to activate?

    From any page, you can get the pointer to the property sheet and call the SetActivePage method to move from page to page. In other words, when the user changes a combobox selection on page 1, you set up an OnSelectChanged handler and then call SetActivePage to take you to Page2, page3, or whatever
    Can you please give me some code sample as to how/where i would do this?

    Thanks

  5. #20
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Design issue

    Post a couple of screen shots of the different pages and I'll mock it up for you.

  6. #21
    Join Date
    Oct 2006
    Posts
    128

    Re: Design issue

    Thanks
    Attached Images Attached Images   

  7. #22
    Join Date
    Oct 2006
    Posts
    128

    Re: Design issue

    HI! Is it possible to have any button in the wizard , Like in my GetReport instead of next, back etc? -SetFinishText() did the trick.

    What i haven't still figured out is how to make the combo decide which page to display.....any help anyone?
    Last edited by rachelason; June 19th, 2008 at 05:49 AM. Reason: editing

  8. #23
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Design issue

    Yes and stay tuned, I'm working on a sample. I'll have it ready later today.

  9. #24
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Design issue

    Here it is.

    This sample is a dialog application that contains a child modeless property sheet and a combobox. When the user makes a combo box selection, the property sheet switches pages.

    I don't have the using the 'property sheet as a document' functionality hooked up yet, but will finish this shortly. Using this technique allows the data for all the pages to be centralized in the sheet (the sheet is used as a document) and virtually eliminates the page to page control interaction that you get without using this technique.
    Attached Images Attached Images    
    Attached Files Attached Files

  10. #25
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Design issue

    The data 'document' portion has been connected. This means the data for each page is stored in a 'document' within the property sheet. Actually the 'document' is a class called CReportDataMgr and it contains a stl::map whose keys are the property page index and whose value is a CReportDataBase derived class. This allow each page to access its underlying data object in a clean manner and apply DDX directly to the data.

    Let's take a look at one of the pages, the Tape Cartridge page. This page has a report, show, and sort comboboxes and a reg ex checkbox and edit control.

    In the OnInitDialog method we retrieve the pointer to the report data (via the property sheet and report data mgr class). This is done in the second line of this method.

    After that we initialize the comboboxes. The report combobox gets filled
    with reports from the underlying report data.

    Code:
    BOOL CTapeCartridgePage::OnInitDialog( )
    {
    	int nIndex = 0;
    
    	m_pReportData = GetReportSheet( )->GetReportDataMgr( ).GetReportData< CRDTapeCartridge* >( PPI_TAPECARTRIDGE );
    
    	ASSERT( NULL != m_pReportData );
    
    	CPropertyPage::OnInitDialog();
    
    	// Walk through the report map and insert the items into the report combobox control
    	REPORT_MAP reportMap = m_pReportData->GetReportMap( );
    	for( REPORT_MAP::iterator it = reportMap.begin( ); it != reportMap.end( ); it++, nIndex++ )
    	{
    		// Display the string and associate the key of the map with the item's data
    		// this allows us to retrieve the key for the selected item.
    		// It allows us more flexibility that just using an index because reports may be added
    		// or removed and not have a sequential index
    		m_ReportCtrl.InsertString( nIndex, (*it).second->GetName( ) );
    		m_ReportCtrl.SetItemData( nIndex, (*it).second->GetIndex( ) );
    	}
    	m_ReportCtrl.SetCurSel( m_pReportData->GetReportIndex( ) );
    
    	// Populate the combo boxes and set their initial position from the report data
    	m_ShowCtrl.InsertString( 0, _T("All") );
    	m_ShowCtrl.InsertString( 1, _T("Some") );
    	m_ShowCtrl.SetCurSel( m_pReportData->GetShowIndex( ) );
    
    	m_SortCtrl.InsertString( 0, _T("Ascending") );
    	m_SortCtrl.InsertString( 1, _T("Descending") );
    	m_SortCtrl.SetCurSel( m_pReportData->GetSortIndex( ) );
    
    	EnableRegExEditCtrl( );
    
    	return TRUE;
    }
    Next we look at the DoDataExchange method. The first part are just the
    standard control mappings (which allows us to manipulate the controls).
    The second part is where it gets interesting. These mappings actually
    map to the underlying report data.

    Code:
    void CTapeCartridgePage::DoDataExchange(CDataExchange* pDX)
    {
    	CPropertyPage::DoDataExchange(pDX);
    
    	// Control mappings
    	DDX_Control(pDX, IDC_SORT, m_SortCtrl);
    	DDX_Control(pDX, IDC_EDIT_REGEX, m_RegExEditCtrl);
    	DDX_Control(pDX, IDC_COMBO_SHOW, m_ShowCtrl);
    
    	// Data mappings (maps data to/from the underlying CRDTapeCartridge object.
    	// This object is located in the CReportDataMgr contained within the property sheet.
    	DDX_Check(pDX, IDC_CHECK_REGEX, m_pReportData->GetRegEx( ) );
    	DDX_CBIndex(pDX, IDC_COMBO_SHOW, m_pReportData->GetShowIndex( ) );
    	DDX_CBIndex(pDX, IDC_SORT, m_pReportData->GetSortIndex( ) );
    	DDX_CBIndex(pDX, IDC_REPORT, m_pReportData->GetReportIndex( ) );
    	DDX_Text( pDX, IDC_EDIT_REGEX, m_pReportData->GetRegExString( ) );
    	DDX_Control(pDX, IDC_REPORT, m_ReportCtrl);
    }
    Now let's look at what happens when the page becomes active. Nothing to
    interesting in the OnSetActive handler. All we do is Enable or disable the
    'Get Report' button (which is actually the Wizard's 'Finish' button that has
    been renamed.

    Code:
    BOOL CTapeCartridgePage::OnSetActive() 
    {
    	GetReportSheet( )->DisplayGetReportButton( TRUE );
    	return CPropertyPage::OnSetActive();
    }
    The last thing to look at is the OnWizardFinish button handler. Because
    we are storing all the data in the underlying m_pReportData variable (which
    for this class is actually a pointer to CRDTapeCartridge object), any changes
    made in this page are saved to this object by UpdateData( ).

    Code:
    // Called when the 'Get Report' button is pressed on this page
    // (which is really the finish button that has been renamed)
    BOOL CTapeCartridgePage::OnWizardFinish() 
    {
    	UpdateData( );
    
    	// Just simulate the report by presenting the underlying data
    	AfxMessageBox( m_pReportData->GetDisplayString( ) );
    	return FALSE;
    }
    The code above just presents a dialog that displays the settings.

    See the attachment for the updated source.

    Note: This project builds and runs in either UNICODE OR MBCS.

    Any comments or suggestions are welcome.
    Attached Files Attached Files

  11. #26
    Join Date
    Oct 2006
    Posts
    128

    Re: Design issue

    Thank you so much Arjay for sparing your time. I appreciate that. Will try what you have posted.

  12. #27
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Design issue

    Your welcome. If you have any feedback, please let me know.

  13. #28
    Join Date
    Oct 2006
    Posts
    128

    Re: Design issue

    HI Arjay, i had been trying to add your method of displaying the dialog in to my existing MDI project. I created all the dialogs in the resource view, created classes for it and as soon as I add the reportsheet, i get error.. like
    Code:
    c2664, CBlankPage::CBlankPage(const CBlankPage&) cannot convert parameter 1 fr4om cReportSheet *const to constCBlankPage&..
    .if i correct this then another.... Ofcourse i ignored everything related to datamanager at this stage.

    If i use your project and added childframe, mainframe, view etc and make it into a MDi project after removing your cwinapp subclass, i can't make the Mainframe object created. Get runtime error at cwinapp subclass.cpp at line 90 where the Cmainframe *pmainframe check is done.

    If i add the doc, view, childframe, mainframe, add headers in the stdafx.h , do i have to do anything else to make the project MDI....

    Thanks again.

  14. #29
    Join Date
    Oct 2006
    Posts
    128

    Re: Design issue

    I realised that i need to update my .rc file also and now it is a MDI project. Will try and see where i get to.
    Thanks

  15. #30
    Join Date
    Sep 2004
    Posts
    1,361

    Re: Design issue

    Arjay, I have been trying to learn to use property sheets. I am very new to doing windows GUI's with MFC and probably am making a very basic mistake. I have tried to use your code as a guide, but things just are not working. I do not "see" any of my property sheets and the following in the main dialog OnInitDialog:
    Code:
    // The following GetclientRect fails.  I have a feeling it doesn't have a properly initalized window or something
    	// Move the property page down a little bit
    	CRect rect;
    	PropSheets->GetClientRect( &rect );
    	rect.top += 30;
    	rect.bottom += 30;
    	PropSheets->MoveWindow( rect );
    fails.

    I have attached my project as a zip. If you run it, you will very quickly get a debug assertion. I have read several tutorials and they all seem to say, Just do these things and it all works magically. I am using VS 2008 if that matters. I created my "MyPropertySheets" class by doing the New-->Class and picking a MFC class, the CPropertySheet class. Maybe this is not the proper way to do that.

    Anyway if you (or someone) can take a look and tell me what I am doing wrong. This is just some code I am writing to learn how to do property sheets so it isn't very neat or well organized.
    Attached Files Attached Files

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured