![]() |
ReportSampleView as an MDI window |
Post Reply ![]() |
Author | |
cdyckes ![]() Newbie ![]() Joined: 14 October 2004 Location: United Kingdom Status: Offline Points: 9 |
![]() ![]() ![]() ![]() ![]() Posted: 25 February 2005 at 10:31am |
I've got a project where I've used the ReportSampleView .cpp and .h as the basis of my view class. My project is an MDI rather than SDI and I've got two questions:- 1) Opening a second view causes a break in the CReportSampleView::OnInitialUpdate() function when the code attempts to subclass IDC_COLUMNLIST and IDC_FILTEREDIT. I know why this fails, but does anyone have any sample code that shows how this should be done? 2) The second question has been addressed on this group, but solved by the original poster without posting the answer:- I need the Field Chooser and Filter Edit dialogs to work with the current active view as the use switches between views. Again any sample code would be much appreciated. Same problem exists with both 9510 and 9600 releases. Thanks Colin |
|
![]() |
|
sserge ![]() Moderator Group ![]() Joined: 01 December 2004 Status: Offline Points: 1297 |
![]() ![]() ![]() ![]() ![]() |
Hello Colin,
The main idea could be to make Field Chooser and Filter Edit dialogs as singletons for the application. It could be done via using static pointers in your view. You'd also have to change dialogs initialization code inside OnInitialUpdate method. Also you have to catch OnActivateView event -- this would allow you to force both dialogs to work with the currently active view. Take a look at the sample code below: // h-File //////////////////////////////////////////////////////////// ////////////// class CReportSampleView : public CView { protected: static CXTPReportSubListControl* ms_pWndSubList; static CXTPReportFilterEditControl* ms_pWndFilterEdit; static int s_nViewsCount; // ... other declarations }; // cpp-File /// //////////////////////////////////////////////////////////// ////////////// CXTPReportSubListControl* CReportSampleView::ms_pWndSubList = NULL; CXTPReportFilterEditControl* CReportSampleView::ms_pWndFilterEdit = NULL; int CReportSampleView::s_nViewsCount = 0; // CReportSampleView construction/destruction CReportSampleView::CReportSampleView() { s_nViewsCount++; } CReportSampleView::~CReportSampleView() { s_nViewsCount--; ASSERT(s_nViewsCount >=0); if(s_nViewsCount == 0) { if(ms_pWndSubList) { ms_pWndSubList->UnsubclassWindow(); delete ms_pWndSubList; ms_pWndSubList = NULL; } if(ms_pWndFilterEdit) { ms_pWndFilterEdit->UnsubclassWindow(); delete ms_pWndFilterEdit; ms_pWndFilterEdit = NULL; } } } void CReportSampleView::OnInitialUpdate() { CView::OnInitialUpdate(); CMainFrame* pWnd = (CMainFrame*)AfxGetMainWnd(); // Init CXTPReportSubListControl if (!ms_pWndSubList) { ms_pWndSubList = new CXTPReportSubListControl(); if (!ms_pWndSubList) return; if (!::IsWindow(ms_pWndSubList->GetSafeHwnd())) { ms_pWndSubList->SubclassDlgItem(IDC_COLUMNLIST, &pWnd->m_wndFieldChooser); m_wndReport.GetColumns()->G etReportHeader()->SetSubListCtrl(ms_pWndSubList); } ms_pWndSubList->SetReportCtrl(&m_wndReport); }   ; // Init CXTPReportFilterEditControl in the same way as above with CXTPReportSubListControl // ... } void CReportSampleView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) { if(bActivate) { if (ms_pWndSubList) { ms_pWndSubList->ResetContent(); ms_pWndSubList->SetReportCtrl(&m_wndReport); } if (ms_pWndFilterEdit) ms_pWndFilterEdit->SetReportCtrl(&m_wndReport); } CView::OnActivateView(bActivate, pActivateView, pDeactiveView); } -- Best regards, Sergey Edited by sserge |
|
![]() |
|
cdyckes ![]() Newbie ![]() Joined: 14 October 2004 Location: United Kingdom Status: Offline Points: 9 |
![]() ![]() ![]() ![]() ![]() |
Sergey, Brilliant!! That does what I need and has saved hours of fumbling around in the dark-space that passes for Xtreme Toolkit documentation One minor problem I've noticed is that this solution leaves the Field Chooser fields at the values last set in any active ReportView, but, more importantly, the Field Chooser loses all of its field entries if all Report views are closed and then a new one opened. I can probably figure that one out myself, but have you by any chance solved this problem as well? (Reached brain saturation point in a mapi in c++ implementation Thanks again Colin |
|
![]() |
|
sserge ![]() Moderator Group ![]() Joined: 01 December 2004 Status: Offline Points: 1297 |
![]() ![]() ![]() ![]() ![]() |
Hi Colin,
Try resetting Field Chooser contents firstly in OnActivateView: if(bActivate) { if (ms_pWndSubList) { ms_pWndSubList->ResetConten t(); ms_pWndSubList->SetReportCt rl(&m_wndReport); } ...... That should help. -- Best regards, Sergey |
|
![]() |
|
cdyckes ![]() Newbie ![]() Joined: 14 October 2004 Location: United Kingdom Status: Offline Points: 9 |
![]() ![]() ![]() ![]() ![]() |
Sergey, I'd tried :- ms_pWndSubList->UpdateList(); which solved the problem of switching between views but not that of closing all views and opening a new one. I just tried your suggestion but that causes an assertion failure when opening a new view having closed all the open views:- _AFXWIN_INLINE void CListBox::ResetContent() m_hWnd is 0 Nearly there I think. Thanks Colin |
|
![]() |
|
sserge ![]() Moderator Group ![]() Joined: 01 December 2004 Status: Offline Points: 1297 |
![]() ![]() ![]() ![]() ![]() |
Hi Colin,
Yep, my solution missed one more thing -- when the last view is closing and we are deleting Field Chooser object inside the View destructor, we should also Unsubclass subclassed window :) So, this piece of code in CReportSampleView::~CReportSampleView() will look in the following way: ..... if(ms_pWndSubList) { ms_pWndSubList->UnsubclassW indow(); delete ms_pWndSubList; ms_pWndSubList = NULL; } ...... And the same for Filter Edit window. -- Best regards, Sergey |
|
![]() |
|
cdyckes ![]() Newbie ![]() Joined: 14 October 2004 Location: United Kingdom Status: Offline Points: 9 |
![]() ![]() ![]() ![]() ![]() |
Hi Sergey, Yep, that works fine, just got to decide what field state gets saved now. Thanks Colin |
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |