Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi Everyone,

In my SDI application,View has two panes(CScrollView,CFormView),and also i am using CSplitterWnd to split the Window.Now i need to send a string from the form to view.Previously I was using the following code to get the view from the dialog box,

CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd();
CView* pCombo1 = pFrame->GetActiveView();

But this is worrking properly with the communication between dialog box and view,.Is there need to change these lines to get the view from form,

Need ur guidance,

Shiva.,
Posted
Updated 11-Mar-10 23:38pm
v2

See also :) :
CWnd* CSplitterWnd::GetPane(int iRow, int iCol) const;
 
Share this answer
 
When your form view is trying to sent a message to your scroll view, it is likely that form view is the active view - which is why your message is going to the wrong place.

I did an app that used lots of views - sometimes in a splitter, sometimes not. If your app is going to become more complex, you might want to consider the approach I used. I created some mix-in classes for the splitter and view classes. The views would then use my "SendToParentWindow" function. If the parent was a splitter, it would then forward the message to its other children. This way, the view didn't have to care where in a splitter it was - or even if it was in a splitter. This allowed me to reuse the same view classes in different situations.
 
Share this answer
 
Here would be a possible way
to iterate all opened documents views (in your case one view) :) :

void CMainFrame::SendStringToOpenedView(const CString& cszMessage)
{
  CWinApp* pcApp = AfxGetApp();
  if (pcApp) {
    POSITION pos = pcApp->GetFirstDocTemplatePosition();
    while (pos) {
      CDocTemplate* pcTemplate = pcApp->GetNextDocTemplate(pos);
      if (pcTemplate) {
        POSITION posDoc = pcTemplate->GetFirstDocPosition();
        while (posDoc) {
          CDocument* pcDoc = pcTemplate->GetNextDoc(posDoc);
          if (pcDoc) {
            POSITION posView = pcDoc->GetFirstViewPosition();
            while (posView) {
              CYourView* pcView = DYNAMIC_DOWNCAST(CYourView, pcDoc->GetNextView(posView));
              if (pcView->GetSafeHwnd()) {
                pcView->TakeString(cszMessage); // :)
              }
            }
          }
        }
      }
    }
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900