Print Page | Close Window

ReportSampleView as an MDI window

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=1860
Printed Date: 11 August 2025 at 10:08am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: ReportSampleView as an MDI window
Posted By: cdyckes
Subject: ReportSampleView as an MDI window
Date 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




Replies:
Posted By: sserge
Date Posted: 01 March 2005 at 2:22am
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


Posted By: cdyckes
Date Posted: 01 March 2005 at 10:32am

Sergey,

Brilliant!!   That does what I need and has saved hours of fumbling around in the dark-space that passes for Xtreme Toolkit documentation .     Thank You!

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



Posted By: sserge
Date Posted: 01 March 2005 at 11:18am
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


Posted By: cdyckes
Date Posted: 01 March 2005 at 11:36am

Sergey,

I'd tried :-

   ms_pWndSubList->UpdateList();
   ms_pWndSubList->SetReportCtrl(&m_wn dReport);

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()
 { ASSERT(::IsWindow(m_hWnd)); ::SendMessage(m_hWnd, LB_RESETCONTENT, 0, 0); }

m_hWnd is 0

Nearly there I think.

Thanks

Colin



Posted By: sserge
Date Posted: 02 March 2005 at 6:25am
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


Posted By: cdyckes
Date Posted: 03 March 2005 at 5:20am

Hi Sergey,

Yep, that works fine, just got to decide what field state gets saved now.

Thanks

Colin




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net