Link to home
Start Free TrialLog in
Avatar of mike_marquet
mike_marquet

asked on

Views in MDI application question !

Hi,

How can I get the number of views opened in my MDI application from the main frame ?

and getting a pointer to a view giving his index ?
Avatar of Vinayak Kumbar
Vinayak Kumbar

Hi,

1. Use MDIGetActive to get the active child wnd
2. Using that child pointer use GetActiveDocument to get the CDocument pointer
3. Then using that CDocument pointer use GetFirstViewPosition and then GetNextView to navigate and get the views.

Try it out.
VinExpert
Avatar of mike_marquet

ASKER

Don't works, I became every 2 views when for example 10 views exist.

Here's the function :

int CMainFrame::GetNumberOfViews()
 {
  CMDIChildWnd *pView = MDIGetActive();

  if (!pView) return 0;

  CDocument *pDocument = pView->GetActiveDocument();

  if (!pDocument) return 1;

  int iNumberOfViews = 1;

  POSITION iPos = pDocument->GetFirstViewPosition();

  while (iPos)
   {
    CView *pView = pDocument->GetNextView(iPos);

    if (pView) iNumberOfViews++;
   }

  return iNumberOfViews;
 }

Step's example :

CreateNewView();
GetNumberOfViews(); // returns 2, must be 1
CreateNewView();
GetNumberOfViews(); // returns 2, OK
CreateNewView();
GetNumberOfViews(); // returns 2, must be 3
CreateNewView();
GetNumberOfViews(); // returns 2, must be 4
CreateNewView();
GetNumberOfViews(); // returns 2, must be 5
CreateNewView();
GetNumberOfViews(); // returns 2, must be 6
CreateNewView();
GetNumberOfViews(); // returns 2, must be 7
CreateNewView();
GetNumberOfViews(); // returns 2, must be 8
CreateNewView();
GetNumberOfViews(); // returns 2, must be 9
CreateNewView();
GetNumberOfViews(); // returns 2, must be 10
I have found the solution.

int CMainFrame::GetNumberOfViews()
 {
  POSITION iPos = theApp.GetFirstDocTemplatePosition();

  if (!iPos) return 0;

  int iNumberOfViews = 0;

  while (iPos)
   {
    iNumberOfViews++;

    theApp.GetNextDocTemplate(iPos);
   }

  return iNumberOfViews;
 }
Cool...

All the best.

VinExpert
mike_marquet,

These questions are still open and our records show you logged in recently. Please resolve them appropriately as soon as possible. Continued disregard of your open questions will result in the force/acceptance of a comment as an answer; other actions affecting your account may also be taken. I will revisit these questions in approximately seven (7) days. Please note that the recommended minimum for an "Easy" question is 50 points.

https://www.experts-exchange.com/jsp/qShow.jsp?qid=11532221
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11701138
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11841838
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11928102
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11931818
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11996498
https://www.experts-exchange.com/jsp/qShow.jsp?qid=11998538
https://www.experts-exchange.com/jsp/qShow.jsp?qid=12011459
https://www.experts-exchange.com/jsp/qShow.jsp?qid=12039459
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20005590
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20006135
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20071202
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20084832
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20091412
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20093693
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20095151
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20099190
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20099158
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20100338
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20107694
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20114039
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20071199
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20116007
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20128382
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20137131
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20155355
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20192497
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20193603
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20238400
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20239471
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20245231
https://www.experts-exchange.com/jsp/qShow.jsp?qid=20253153

EXPERTS: Please leave your thoughts on this question here.

Thanks,

Netminder
Community Support Moderator
Experts Exchange
ASKER CERTIFIED SOLUTION
Avatar of Netminder
Netminder

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