Link to home
Start Free TrialLog in
Avatar of gurukg102498
gurukg102498

asked on

MDI - Multiple Views Single Doc

Hi,

I have a MDI based application with 2 views.
Left Hand side view is CTreeView and the right side view is CListView.Whenever I click an item on the lreft view corresponding data will get displayed in the List view sim ilar to EXPLORER application.

Now i want to implement the following :

1 ) On Click of File->new or Window->New Window Menu Items, another window (child window) of same type has to be created.i.e say if I have selected the node X in first window (tree control in the first window), then On CLick of New another window of CTreeCtrl on the Left hand side and a list view on the Right hand side with the node selected in the first window has to be shown.Its corresponding data has to be displayed in the list view.Hope I am clear in my explanation.

For the above problem : we can do Serializing the contents of tree control to a file and we can create a Document template.But the problem is we may have a max of 30,000 entries in the tree control.

2 ) If I edit any node in the tree control of one window, then it has to be reflected immdly in all the other OPENED WINDOWS.

Pls advice me on how to implement the same.

If you help me with an example your help would be appreciated.

This is very urgent.

Regds


Avatar of migel
migel

Hi to create new window you can use
such code:
{
CWnd* pWnd = AfxGetMainWnd();
if (pWnd)
{
pWnd->SendMessage(WM_COMAND, ID_WINDOW_NEW, 0);
}
}

this code create exactly same frame as your current.
to reflect changes from one frame to the another ones, use

void CDocument::UpdateAllViews(CView* pSender, LPARAM lHint, CObject* pHint)
{
}

If you want I can create test project and send it to you.
Avatar of gurukg102498

ASKER

Hi Migel,
Thanks for your suggestions.

Could you tell me how will call UpdateAllViews(0 method.

My tree control can have a max of 30,000 entries.Ok.I need to have a doc pointer to call UpdateAllViews() method.

Could you tell me how will I store the contents of the entire tree control in a DOC TEMPLATE so that i can call UpdateAllViews() method to reflect the changes I make in one view will reflect all the others immdly.

Migel, I would appreciate if you could send me a test project immdly.

Migel could yopu give me your mail id.

guru
my eMail is: migel.geo@yahoo.com
I sent modified project to you
Hi Migel,
Thanks for that.

But it does not have any files inside the zip.

Pls, COuld you resend that again.

Thanks,
guru
void CLeftView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)
{
     NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
     // TODO: Add your control notification handler code here
     if (m_bInUpdateSemaphore)
          return;
     
     CTreeCtrl& Ctrl = GetTreeCtrl();
     HTREEITEM hti = Ctrl.GetSelectedItem();
     CString str;
     BuildTreePath(hti, str);

     GetDocument()->UpdateAllViews(this, HINT_SELCHANGED, (CObject*)&str);
     *pResult = 0;
}

void CLeftView::OnItemexpanded(NMHDR* pNMHDR, LRESULT* pResult)
{
     NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
     // TODO: Add your control notification handler code here
     if (m_bInUpdateSemaphore)
          return;
     CTreeCtrl& Ctrl = GetTreeCtrl();
     HTREEITEM hti = pNMTreeView->itemNew.hItem;
     CString str;
     BuildTreePath(hti, str);

     long lHint = 0;
     if (pNMTreeView->action == TVE_EXPAND)
          lHint = HINT_ITEMEXPANDED;
     if (pNMTreeView->action == TVE_COLLAPSE)
          lHint = HINT_ITEMCOLLAPSED;
     GetDocument()->UpdateAllViews(this,  lHint, (CObject*)&str);
     
     *pResult = 0;
}

void CLeftView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
     if (pSender == this)
          return;
     if (lHint >= HINT_SELCHANGED && lHint <= HINT_ITEMCOLLAPSED)
          {
          CString strParam = *((CString*) pHint);
          CTreeCtrl& Ctrl = GetTreeCtrl();
          HTREEITEM hti = Ctrl.GetRootItem();
          int nIndex = strParam.Find('\n');
          if (nIndex != -1)
               {
               hti = Ctrl.GetChildItem(hti);
               m_bInUpdateSemaphore = TRUE;
               CString strFind = strParam.Left(nIndex);
               strParam= strParam.Right(strParam.GetLength()-nIndex-1);
               
               while (hti)
                    {
                    CString str = Ctrl.GetItemText(hti);
                    if (strFind == str)
                         {
                         Ctrl.Expand(Ctrl.GetParentItem(hti), TVE_EXPAND);
                         nIndex = strParam.Find('\n');
                         if (nIndex == -1)
                              break;
                         hti = Ctrl.GetChildItem(hti);
                         strFind = strParam.Left(nIndex);
                         strParam = strParam.Right(strParam.GetLength()-nIndex-1);
                         }
                    else
                         hti = Ctrl.GetNextSiblingItem(hti);
                    }
               }
          if (hti)
               {
               switch (lHint)
                    {
                    case HINT_SELCHANGED:
                         Ctrl.SelectItem(hti);
                         break;
                    case HINT_ITEMEXPANDED:
                         Ctrl.Expand(hti, TVE_EXPAND);
                         break;
                    case HINT_ITEMCOLLAPSED:
                         Ctrl.Expand(hti, TVE_COLLAPSE);
                         break;
                    }
               }
          m_bInUpdateSemaphore = FALSE;
          }
}

void CLeftView::BuildTreePath(HTREEITEM hti, CString &strPath)
{
     CString strTemp;
     CTreeCtrl& Ctrl = GetTreeCtrl();
     strPath.Empty();
     while(hti != Ctrl.GetRootItem())
          {
          strTemp = Ctrl.GetItemText(hti);
          strTemp += "\n";
          strPath = strTemp+strPath;
          hti = Ctrl.GetParentItem(hti);
          }
}
that is you must add handlers for next TVN_ reflecton messages (in the IDE class view)
     ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
     ON_NOTIFY_REFLECT(TVN_ITEMEXPANDED, OnItemexpanded)
Hi Migel,
Thanks.
I will work on this and get back to you.

Thanks a lot.

Hi Migel,
When I compile the workspace with the changes suggested by you I am getting COmpilation errors.Hence I have sent the modified workspace to your other id.

Pls do the needful.

Thanks.
Migel,

Thanks for sending the files.
But still it gave compilation erros.

HINT_ITEMEXPANDED,HITN_ITEMCOLLAPSED and HINT_SELCHANGED were given Undeclared identifiers.So I included the following in the TestExp1Doc.h

# define HINT_ITEXPANDED 0
# define HINT_ITEMCOLLAPSED 1
# define HINT_SELCHANGED 2

Then compiled the workspace.No error.But when I execute it, an exception was thrown in OnUpdate() method. The parameter pHint is NULL.

Could u help me in fixing this.

Thanks.

Will send you the workspace.
Migel, You would have received my workspace.

Do I need to change the values of # define ?

I changed the #define values from 0 to 1.So the testExpdoc.h has the following values :

# define HINT_ITEMEXPANDED 3
# define HINT_ITEMCOLLAPSED 2
# define HINT_SELCHANGED    1

When I executed the exe NO EXCEPTION was thrown.

When I select an item in the first window and do a click->File->New window, the same item is selected again.Good.

But when I expand any node in that tree control it is not getting reflected back in the other windows (i.e other tree controls).

Pls help me in fixing this bug.

My NEED is :

Whatever I do(EDIT,EXPAND,COLLAPSE etc..) in a current active window, SHOULD GET IMMEDIATELY REFLECTED IN THE OTHER OPENED NON ACTIVE WINDOWS IMMEDIATELY.



Thanks
Hello guru
Hm so terrible
I send project to you it almost satisfy your requirements except node editing:
to do that you need handle
TVN_BEGINEDITLABEL - here you must store item label
and
TVN_ENDEDITLABEL - here you must send update information to the another views to replace text
or you want that I do it for you?
ASKER CERTIFIED SOLUTION
Avatar of migel
migel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello gurukg:

You have far too many old questions that remain open to honestly request answers to more. I will be watching for you to clean them up.

If you need assistance, just let me know.
amp
Community Support Moderator
Experts Exchange
Admin notified of User neglect. Force-accepted by
Netminder
CS Moderator