Solved

views and docs

Posted on 2001-06-06
3
208 Views
Last Modified: 2013-11-20
i have 2 problems:
1. i need to prevent from documents to be created in some conditions, how to do it?
2. i need to draw on the a 2nd view in a coordinates of the corsor which is in the first view, and only there, how to loop for the view? (which is not this pointer)

thanks
0
Comment
Question by:web37
  • 2
3 Comments
 
LVL 12

Expert Comment

by:migel
ID: 6159034
Hi!
UpdateAllViews with proper hint will help you to part2.
for part1
IMHO you have to derive class DocTemplate and override virtual CDocument* CreateNewDocument(); method
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 40 total points
ID: 6159062
for Q1:

in OnNewDocument of your Doc class add a condition before the creation:
m_bAllowCreateDocs is a data member in the app or main frame which is false in the cinstructor and true when u allow creating of docs

BOOL CMyDoc::OnNewDocument()
{
if(m_bAllowCreateDocs)
     if (CDocument::OnNewDocument())
               return TRUE;

     return TRUE;
}

for Q2 is a bit longer:
1. add this member to your CApp class ->      CMultiDocTemplate* m_ptrDocTemplate;
and initialize it in the InitInstance():
     CMultiDocTemplate* pDocTemplate;
     pDocTemplate = new CMultiDocTemplate(
          IDR_DBLCURTYPE,
          RUNTIME_CLASS(CMyDoc),
          RUNTIME_CLASS(CChildFrame), // custom MDI child frame
          RUNTIME_CLASS(CMyView));
     AddDocTemplate(pDocTemplate);
     m_ptrDocTemplate = pDocTemplate; //saving pointer to the doc template


2.add a function to the app called GetNumOfOpenWindows():
UINT CDblCursorApp::GetNumOfOpenWindows()
{
     UINT uNumOfOpenWindows = 0;
     POSITION pos = m_ptrDocTemplate->GetFirstDocPosition();
     CDblCursorDoc* pDoc;
     CDblCursorView* pView;

     while ( pos != NULL ) {
          pDoc = (CMyDoc*)(m_ptrDocTemplate->GetNextDoc(pos));
          ASSERT(pDoc);
          POSITION posView = pDoc->GetFirstViewPosition();

          while( posView != NULL ) {
               pView = (CMyView*)pDoc->GetNextView(posView);
               ASSERT(pView);

               uNumOfOpenWindows++;
          }
     }

     return uNumOfOpenWindows;
}

3.override OnMouseMove of your CVIew:
void CDblCursorView::OnMouseMove(UINT nFlags, CPoint point)
{
     if(((CDblCursorApp*)AfxGetApp())->GetNumOfOpenWindows())     {
          CMultiDocTemplate* pDT = ((CMyApp*)AfxGetApp())->GetDocTemplate();
          POSITION pos = pDT->GetFirstDocPosition();
          CMyDoc* pDoc;
          CMyView* pView;

          while ( pos != NULL ) {
               pDoc = (CMyDoc*)(pDT->GetNextDoc(pos));
               POSITION posView = pDoc->GetFirstViewPosition();

               while(posView != NULL) {
                    pView = (CMyView*)pDoc->GetNextView(posView);
                    if(pView == this)
                         continue;//skip special drawing on your view !!!

                    pView->DoSpecialDraw(point);
               }
          }
     }
     CView::OnMouseMove(nFlags, point);
}

4.add a special drawing function to your view:
void CMyView::MoveCursorPos(CPoint point)
{
//here add your special drawing code with the point from the 1st view
}

good luck


0
 
LVL 42

Expert Comment

by:sedgwick
ID: 6159196
instead of void CMyView::MoveCursorPos(CPoint point)
it should be void CMyView::DoSpecialDraw(CPoint point)

cheers mate
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
dog bark java program 15 82
either24  challenge 19 84
Fibonacci challenge 11 84
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 88
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now