Enumerare documente si view-uri

Intrebari legate de programarea cu biblioteci precum MFC, ATL, WTL si GDI+.
Post Reply
mesajflaviu
Membru++
Membru++
Posts: 687
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Enumerare documente si view-uri

Post by mesajflaviu » 07 Oct 2011, 10:09

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 ?



User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3778
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: Enumerare documente si view-uri

Post by Ovidiu Cucu » 07 Oct 2011, 11:13

SetForegroundWindow are efect asupra ferestrelor top-level nu si asupra celor child asa cum este un view.

Vezi:

User avatar
bu7ch3r
Membru++
Membru++
Posts: 326
Joined: 17 May 2011, 15:17
Judet: Iaşi
Location: Sofia
Contact:

Re: Enumerare documente si view-uri

Post by bu7ch3r » 07 Oct 2011, 11:58

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
Cu stima,
Lupu Claudiu

mesajflaviu
Membru++
Membru++
Posts: 687
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Re: Enumerare documente si view-uri

Post by mesajflaviu » 07 Oct 2011, 18:55

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);
	}

mesajflaviu
Membru++
Membru++
Posts: 687
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Re: Enumerare documente si view-uri

Post by mesajflaviu » 07 Oct 2011, 19:03

Code: Select all

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

User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3778
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: Enumerare documente si view-uri

Post by Ovidiu Cucu » 08 Oct 2011, 09:12

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.

User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3778
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: Enumerare documente si view-uri

Post by Ovidiu Cucu » 08 Oct 2011, 18:06

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 302 times
Daca sunt neclaritati in programel, te rog intreaba.

mesajflaviu
Membru++
Membru++
Posts: 687
Joined: 10 Sep 2008, 21:40
Judet: Cluj

Re: Enumerare documente si view-uri

Post by mesajflaviu » 10 Oct 2011, 16:11

E ceea ce vroiam (cu mica exceptie), si imi place ca are alta abordare decat ce am incercat eu. Multumesc inca o data !

Post Reply