Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - ReportSampleView as an MDI window
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

ReportSampleView as an MDI window

 Post Reply Post Reply
Author
Message
cdyckes View Drop Down
Newbie
Newbie


Joined: 14 October 2004
Location: United Kingdom
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote cdyckes Quote  Post ReplyReply Direct Link To This Post Topic: ReportSampleView as an MDI window
    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

Back to Top
sserge View Drop Down
Moderator Group
Moderator Group


Joined: 01 December 2004
Status: Offline
Points: 1297
Post Options Post Options   Thanks (0) Thanks(0)   Quote sserge Quote  Post ReplyReply Direct Link To This Post 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

Edited by sserge
Back to Top
cdyckes View Drop Down
Newbie
Newbie


Joined: 14 October 2004
Location: United Kingdom
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote cdyckes Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
sserge View Drop Down
Moderator Group
Moderator Group


Joined: 01 December 2004
Status: Offline
Points: 1297
Post Options Post Options   Thanks (0) Thanks(0)   Quote sserge Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
cdyckes View Drop Down
Newbie
Newbie


Joined: 14 October 2004
Location: United Kingdom
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote cdyckes Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
sserge View Drop Down
Moderator Group
Moderator Group


Joined: 01 December 2004
Status: Offline
Points: 1297
Post Options Post Options   Thanks (0) Thanks(0)   Quote sserge Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
cdyckes View Drop Down
Newbie
Newbie


Joined: 14 October 2004
Location: United Kingdom
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote cdyckes Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.043 seconds.