15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Menu controls view, doc or main frame ? Which the better ?

Pedro Vicente -- vicente@hidro1.ist.utl.pt
Wednesday, April 03, 1996

Environment: VC++ 4.0 / Win 95

Hi all

I' m doing a program that does some numeric calculus.
I put the data inside a CDocument and displayed the data
on a CView (the app is MDI).
I have two diferent  views of the doc. The user
controls the numeric calculation by the menu (options like
Start, stop , trace and clear ), which acts on a timer.

What I did first was to define the ID_COMMAND function
controled by one view. This works fine, but the other
view does not react, except on a Paint message. I tried 

pDocument->UpdateAllViews( this );

inside the current view. Ok, the other view gets updated but
the view's client area gets terribly flickering ( it does a BitBlt
of a bitmap).

I tried another approach: the menu controls the CMainFrame
instead (i.e the timer is on CMainFrame). 
The same happened, with the disavantege of some complex 
window accessing:

void CMainFrame::OnTimer(UINT nIDEvent) 
{
 // TODO: Add your message handler code here and/or call default

 CMDIChildWnd* pActiveChild = MDIGetActive();
 if ( pActiveChild ) {

  CHidroDoc* pDocument = (CHidroDoc*) pActiveChild->GetActiveDocument();
  pDocument->transfer.hydro_1D->Iterar();
  pDocument->UpdateAllViews( NULL );
 }
	
 CMDIFrameWnd::OnTimer(nIDEvent);
}


I suspect that if I tranfer the timer directly to the document the same
flicker occurs on the views. Anyway what is the best place
to put the timer , i.e, the best place to define the ID_COMMAND
menu messages : inside one view, the doc, the MDI main frame
or the MDIChildFrame ?

Pedro Vicente






nicolas@dsys.ceng.cea.fr
Friday, April 05, 1996

> [...] This works fine, but the other
> view does not react, except on a Paint message. I tried 
> 
> pDocument->UpdateAllViews( this );
> 
> inside the current view. Ok, the other view gets updated but
> the view's client area gets terribly flickering ( it does a BitBlt
> of a bitmap).
> [...]

You didn't focused on the problem. Whatever where you call your
view's update, you will have flickering. This is because Windows
paint an uniform background, and AFTER you paint your bitmap.

The way of avoiding this is to prevent windows to draw the background.

Just add one OnEraseBackground() function (with Class Wizard) in your
views and do nothing in it. You will no more have flickering.

Hope it helps.

----
Eric Nicolas 

Take a look to the SWORD home page :
	http://mimine.iut.univ-metz.fr/~borysgr/sword.web/home.html
 



Darius Thabit -- darius@world.std.com
Friday, April 05, 1996

[Mini-digest: 2 responses]


> I tried 
> 
> pDocument->UpdateAllViews( this );
> 
> inside the current view. Ok, the other view gets updated but
> the view's client area gets terribly flickering ( it does a BitBlt
> of a bitmap).

   What you can do is define a "hint" code (or hint structure, if you need 
more parameters - this must be derived from CObject) that can represent the 
various update possibilities for your document, and which takes into account 
the corresponding sub-tasks for your views.  You pass this to 
UpdateAllViews, which gets routed to your view's OnUpdate, which can then 
check the hint parameter for non-null and do the required subtask; 
otherherwise pass off the call to your view base class, which updates the 
entire view.  See the docs for CView::OnUpdate() for more details.

-----From: Dan Kirby 

Hi,

UpdateAllViews calls OnUpdate() for each of your views.  In OnUpdate, MFC 
calls Invalidate(TRUE).  This is causing the view to be repainted and you 
will see the flickering.  If you want to modify what happens when the view 
gets updated, override OnUpdate.

--dan



Pedro Vicente -- vicente@hidro1.ist.utl.pt
Sunday, April 07, 1996

Hi

Thanks for the suggestion. I think I found a better method
instead. With your approach I would have to implemt
a different timer for each view, right ?

I implement this timer * only * for the main frame, an then loop
by the views :

void CMainFrame::Run()
{

CMDIChildWnd* pActiveChild = MDIGetActive();

 if ( pActiveChild ) { //necessario por causa da toolbar

CHidroDoc* pDocument = (CHidroDoc*)pActiveChild->GetActiveDocument();
 pDocument->transfer.hydro_1D->Iterar();

	//iterar pela lista de views do doc
  
  POSITION pos = pDocument->GetFirstViewPosition();
  while ( pos != NULL )
   {
      CBaseView* pView = (CBaseView*)pDocument->GetNextView(pos);
      pView->Show();
						
   } 

}  //if ( pActiveChild )

}


Here Show is a virtual method that each view has.

Pedro Vicente




----------
From: 	Darius Thabit[SMTP:darius@world.std.com]
Sent: 	sabado, 6 de abril de 1996 1:18
To: 	vicente@hidro1.ist.utl.pt
Cc: 	mfc-l@netcom.com
Subject: 	Re: Menu controls view, doc or main frame ? Which the better ?

[Mini-digest: 2 responses]


> I tried 
> 
> pDocument->UpdateAllViews( this );
> 
> inside the current view. Ok, the other view gets updated but
> the view's client area gets terribly flickering ( it does a BitBlt
> of a bitmap).

   What you can do is define a "hint" code (or hint structure, if you need 
more parameters - this must be derived from CObject) that can represent the 
various update possibilities for your document, and which takes into account 
the corresponding sub-tasks for your views.  You pass this to 
UpdateAllViews, which gets routed to your view's OnUpdate, which can then 
check the hint parameter for non-null and do the required subtask; 
otherherwise pass off the call to your view base class, which updates the 
entire view.  See the docs for CView::OnUpdate() for more details.

-----From: Dan Kirby 

Hi,

UpdateAllViews calls OnUpdate() for each of your views.  In OnUpdate, MFC 
calls Invalidate(TRUE).  This is causing the view to be repainted and you 
will see the flickering.  If you want to modify what happens when the view 
gets updated, override OnUpdate.

--dan





Pedro Vicente -- vicente@hidro1.ist.utl.pt
Monday, April 08, 1996

Hi

Thanks for the suggestion. I think I found a better method
instead. With your approach I would have to implemt
a different timer for each view, right ?

I implement this timer * only * for the main frame, an then loop
by the views :

void CMainFrame::Run()
{

CMDIChildWnd* pActiveChild = MDIGetActive();

 if ( pActiveChild ) { //necessario por causa da toolbar

CHidroDoc* pDocument = (CHidroDoc*)pActiveChild->GetActiveDocument();
 pDocument->transfer.hydro_1D->Iterar();

	//iterar pela lista de views do doc
  
  POSITION pos = pDocument->GetFirstViewPosition();
  while ( pos != NULL )
   {
      CBaseView* pView = (CBaseView*)pDocument->GetNextView(pos);
      pView->Show();
						
   } 

}  //if ( pActiveChild )

}


Here Show is a virtual method that each view has.

Pedro Vicente

----
Pedro Vicente 

Take a look at the MARETEC home page :
  http://hidro1.ist.utl.pt

----------
From: 	nicolas@jupiter.ceng.cea.fr[SMTP:nicolas@jupiter.ceng.cea.fr]
Sent: 	sexta-feira, 5 de abril de 1996 15:06
To: 	mfc-l@netcom.com
Subject: 	Re: Menu controls view, doc or main frame ? Which the better ?

> [...] This works fine, but the other
> view does not react, except on a Paint message. I tried 
> 
> pDocument->UpdateAllViews( this );
> 
> inside the current view. Ok, the other view gets updated but
> the view's client area gets terribly flickering ( it does a BitBlt
> of a bitmap).
> [...]

You didn't focused on the problem. Whatever where you call your
view's update, you will have flickering. This is because Windows
paint an uniform background, and AFTER you paint your bitmap.

The way of avoiding this is to prevent windows to draw the background.

Just add one OnEraseBackground() function (with Class Wizard) in your
views and do nothing in it. You will no more have flickering.

Hope it helps.

----
Eric Nicolas 

Take a look to the SWORD home page :
	http://mimine.iut.univ-metz.fr/~borysgr/sword.web/home.html
 






| Вернуться в корень Архива |