Page 1 of 1

Enumerare documente si view-uri

Posted: 07 Oct 2011, 10:09
by mesajflaviu
Intr-o aplicatie MDI am mai multe tipuri de documente : CMy1Doc cu view-ul de tip CScrollView, CMy2Doc cu view-ul de tip CFormView si CMy3Doc cu view-ul de tip CListView. As vrea ca un tip de document sa fie deschis o singura data. Am incercat codul de mai jos care cauta daca CMy2Doc este deschis, daca da il aduce ca fereastra foreground, daca nu il deschide :

Code: Select all

	POSITION posTemplate = theApp.GetFirstDocTemplatePosition();
	while(posTemplate)
	{
		CDocTemplate* pDocTemplate = theApp.GetNextDocTemplate(posTemplate);
		POSITION posDoc = pDocTemplate->GetFirstDocPosition();
		while(posDoc)
		{
			CDocument* pDoc = pDocTemplate->GetNextDoc(posDoc);
			if(pDoc->IsKindOf(RUNTIME_CLASS(CMy2Doc)))
			{
				POSITION posView = pDoc->GetFirstViewPosition();
				if(posView)
				{
					CView* pView = pDoc->GetNextView(posView);
					pView->SetForegroundWindow();
                                                                                TRACE("we found the CMy2Doc\n");
				}
				return;
			}
		}
	}
                // we didn't found CMy2Doc, so we will open it
	POSITION pos = theApp.GetFirstDocTemplatePosition();
	CMultiDocTemplate* pDocTemplate = (CMultiDocTemplate*)theApp.GetNextDocTemplate(pos);
	if(pos)
	{
		pDocTemplate = (CMultiDocTemplate*)theApp.GetNextDocTemplate(pos);
		pDocTemplate = (CMultiDocTemplate*)theApp.GetNextDocTemplate(pos);
		if(pDocTemplate)pDocTemplate->OpenDocumentFile(NULL);
	}

dar ramane o problema : desi gasesc view-ul de tip CMy2View nu resusesc sa il aduc ca fereastra foreground ... adica pView->SetForegroundWindow(); nu are efect ... de ce ?

Re: Enumerare documente si view-uri

Posted: 07 Oct 2011, 11:13
by Ovidiu Cucu
SetForegroundWindow are efect asupra ferestrelor top-level nu si asupra celor child asa cum este un view.

Vezi:

Re: Enumerare documente si view-uri

Posted: 07 Oct 2011, 11:58
by bu7ch3r
Incearca cu : void BringWindowToTop( );

MSDN spune:
In addition, BringWindowToTop activates pop-up, top-level, and MDI child windows. The BringWindowToTop member function should be used to uncover any window that is partially or completely obscured by any overlapping windows.
Suna bine :P

http://msdn.microsoft.com/en-us/library ... s.80).aspx

Re: Enumerare documente si view-uri

Posted: 07 Oct 2011, 18:55
by mesajflaviu
Am incercat codul urmator, nu e elegant, in sensul ca aduce view dupa view si nu e estetic, dar merge SetForegroundWindow :

Code: Select all

	BOOL bMaximized;
	for(int i = 0; i < 5;++i)
	{
		CMDIChildWnd* pChild = (CMDIChildWnd*)MDIGetActive(&bMaximized);
		if(pChild != NULL)
		{
			CMy1View* pView = (CMy1View*)pChild->GetActiveView();
			if(pView->IsKindOf(RUNTIME_CLASS(CMy1View)))
			{
				pView->SetForegroundWindow();
				return;
			}
			MDINext();
		}
	}

	POSITION pos = theApp.GetFirstDocTemplatePosition();
	CMultiDocTemplate* pDocTemplate = (CMultiDocTemplate*)theApp.GetNextDocTemplate(pos);
	if(pos)
	{
		pDocTemplate = (CMultiDocTemplate*)theApp.GetNextDocTemplate(pos);
		pDocTemplate = (CMultiDocTemplate*)theApp.GetNextDocTemplate(pos);
		if(pDocTemplate)pDocTemplate->OpenDocumentFile(NULL);
	}

Re: Enumerare documente si view-uri

Posted: 07 Oct 2011, 19:03
by mesajflaviu

Code: Select all

pView->GetParentFrame()->BringWindowToTop();
merge.

Re: Enumerare documente si view-uri

Posted: 08 Oct 2011, 09:12
by Ovidiu Cucu

Code: Select all

   BOOL bMaximized;
   for(int i = 0; i < 5;++i)
   {
      CMDIChildWnd* pChild = (CMDIChildWnd*)MDIGetActive(&bMaximized);
      if(pChild != NULL)
      {
         CMy1View* pView = (CMy1View*)pChild->GetActiveView();
         if(pView->IsKindOf(RUNTIME_CLASS(CMy1View)))
         {
            pView->SetForegroundWindow();
            return;
         }
         MDINext();
      }
   }
Nu numai ca nu-i estetic dar SetForegroundWindow e pus acolo degeaba. Vezi primul meu post.
Of course, solutia e asa cum a spus bu7ch3r: BringWindowToTop (sau SetWindowPos) pentru frame-ul MDI-child care contine view-ul cautat.

Si, referitor la "estetica": nu te baza ca ai un numar fix de template-uri / frame-uri / view-uri / etc si nici pe ordinea lor. In plus, incearca sa pui functiile care cauta ceva prin toata aplicatia (de exemplu, un view) in clasa aplicatiei (cea derivata din CWinApp).
Nu le imprastia peste tot (ca deh, avem un theApp la indemana :)), altfel n-o sa mai stii nici tu care si pe unde-s.

Re: Enumerare documente si view-uri

Posted: 08 Oct 2011, 18:06
by Ovidiu Cucu
Gasesti in zipul atasat cam cum ma gandesc eu ca trebuie facut.
View-urile le poti deschide/inchide din meniul "View".
Metodele corespunzatoare sunt CTest_MDIApp::ShowView si CTest_MDIApp::CloseView.
Test_MDI.zip
(21.64 KiB) Downloaded 311 times
Daca sunt neclaritati in programel, te rog intreaba.

Re: Enumerare documente si view-uri

Posted: 10 Oct 2011, 16:11
by mesajflaviu
E ceea ce vroiam (cu mica exceptie), si imi place ca are alta abordare decat ce am incercat eu. Multumesc inca o data !