P
Phillip N Rounds
I have an application which is heavily graphics intensive, all the graphics
being custom.
Scattered throughout by app, I have
MyView->OnDraw( this->GetDC() );
Apparently, each call to this->GetDC() creates a GDI object and, 16,000 or
so calls to OnDraw() results in the Application hanging because it can no
longer create any new GDI objects ( I know, 16,384 )
I tried
CDC* pTheDC = this->GetDC();
this->OnDraw( pTheDC );
pTheDC->DeleteDC();
This took care of the GDI leak, but causes problems elsewhere, specfically
in the CView::OnPaint() which calls CView::OnDraw( locally created DC )
which destroys the locally created DC somewhere.
I tried to declare a global CDC* pTheDC in the MyView, instantiate it in
OnInitialUpdate(), and where ever I need to call OnDraw(), implement
if ( pTheDC == NULL ) pTheDC = this->GetDC();
this->OnDraw( pTheDC );
And dispose of pTheDC somewhere appropriate. This fails somewhere down the
line. My OnDraw( ) function does some checking, and based on some factors
either does or does not call
ClearDrawingPalette( CDC* pDC);
DrawTitle( CDC* pDC);
DrawLegend( CDC* pDC);
DrawFootNote( CDC* pDC);
then calls
DrawMyStuff( CDC* pDC );
The above call to OnDraw( pTheDC) fails in one of the subsequent graphics
calls, whereas it does not in the original OnDraw( this->GetDC() );
How do I do this correctly?
TIA
Phil
being custom.
Scattered throughout by app, I have
MyView->OnDraw( this->GetDC() );
Apparently, each call to this->GetDC() creates a GDI object and, 16,000 or
so calls to OnDraw() results in the Application hanging because it can no
longer create any new GDI objects ( I know, 16,384 )
I tried
CDC* pTheDC = this->GetDC();
this->OnDraw( pTheDC );
pTheDC->DeleteDC();
This took care of the GDI leak, but causes problems elsewhere, specfically
in the CView::OnPaint() which calls CView::OnDraw( locally created DC )
which destroys the locally created DC somewhere.
I tried to declare a global CDC* pTheDC in the MyView, instantiate it in
OnInitialUpdate(), and where ever I need to call OnDraw(), implement
if ( pTheDC == NULL ) pTheDC = this->GetDC();
this->OnDraw( pTheDC );
And dispose of pTheDC somewhere appropriate. This fails somewhere down the
line. My OnDraw( ) function does some checking, and based on some factors
either does or does not call
ClearDrawingPalette( CDC* pDC);
DrawTitle( CDC* pDC);
DrawLegend( CDC* pDC);
DrawFootNote( CDC* pDC);
then calls
DrawMyStuff( CDC* pDC );
The above call to OnDraw( pTheDC) fails in one of the subsequent graphics
calls, whereas it does not in the original OnDraw( this->GetDC() );
How do I do this correctly?
TIA
Phil