Ok, i will put code to check if HDC become null.
this is the code, i cut the lees important code because it's bit long
void CNavionicsView::OnDraw(CDC* pDC)
{
CNavionicsDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
int iwkViewOptionApplied=0;
try
{
if (m_CEChartViewAttached !=NULL)
{
...
int iViewSizeX =m_CEChartViewAttached->GetViewSizeX();
int iViewSizeY =m_CEChartViewAttached->GetViewSizeY();
if (m_ToBeRedraw == true)
{
int iSysMetricsX = GetSystemMetrics(SM_CXSCREEN);
int iSysMetricsY = GetSystemMetrics(SM_CYSCREEN);
if( theApp.GetTraceLevel() & (1 << (TRACE_VIEW-1)) ){
CString s; s.Format("CNavionicsView::OnDraw: iSysMetricsX=%d, iSysMetricsY=%d\n",
iSysMetricsX, iSysMetricsY);
OutputDebugString(s);
}
m_MemDC.SelectObject(&m_Brush);
m_MemDC.PatBlt(0,0,iSysMetricsX,iSysMetricsY,PATCOPY);
BeginWaitCursor();
TRACE("OnDraw: m_CEChartViewAttached->Draw...\n");
m_CEChartViewAttached->Draw(m_MemDC.m_hDC);
TRACE("OnDraw: m_CEChartViewAttached->Draw: Done!\n");
EndWaitCursor();
if( theApp.GetTraceLevel() & (1 << (TRACE_VIEW-1)) ){
CString s; s.Format("CNavionicsView::OnDraw: iViewSizeX=%d, iViewSizeY=%d\n",
iViewSizeX, iViewSizeY);
OutputDebugString(s);
}
CNChartView::DrawMarkers(&m_MemDC);
CNChartView::DrawRoutes(&m_MemDC);
CNChartView::DrawAreas(&m_MemDC);
if(theApp.m_bDrawReticolo)
CNChartView::DrawParalelMeridian(&m_MemDC);
m_MemDC2.BitBlt(0,0,iViewSizeX, iViewSizeY, &m_MemDC, 0,0,SRCCOPY );
CNChartView::OnDraw(&m_MemDC2);
if(m_bViewNocturne){
Graphics gx(m_MemDC2);
SolidBrush blackBrush(Color(180,0,0,0));
gx.FillRectangle(&blackBrush,0,0,iViewSizeX,iViewSizeY);
}
pDC->AssertValid();
pDC->BitBlt(0,0,iViewSizeX, iViewSizeY, &m_MemDC2, 0,0,SRCCOPY );
#endif
m_ToBeRedraw = false;
}
else
{
if( theApp.GetTraceLevel() & (1 << (TRACE_VIEW-1)) ){
CString s; s.Format("CNavionicsView::OnDraw: BitBlt\n");
OutputDebugString(s);
}
m_MemDC2.BitBlt(0,0,iViewSizeX, iViewSizeY, &m_MemDC, 0,0,SRCCOPY );
CNChartView::OnDraw(&m_MemDC2);
if(m_bViewNocturne ){
Graphics gx(m_MemDC2);
SolidBrush blackBrush(Color(180,0,0,0));
gx.FillRectangle(&blackBrush,0,0,iViewSizeX,iViewSizeY);
}
pDC->BitBlt(0,0,
iViewSizeX,
iViewSizeY,
&m_MemDC2,0,0,SRCCOPY);
}
}
}
catch(CNavionicsException CNEwkNavionicsException)
{
int iwkErrorNumber
= CNEwkNavionicsException.GetErrorNumber();
if(iwkErrorNumber>=9000 && iwkErrorNumber<=9900)
{
string swkErrorText;
CNEwkNavionicsException.MessageFormatted(swkErrorText, false);
MessageBox((swkErrorText.c_str()), "Fatal Error", MB_OK || MB_ICONEXCLAMATION);
abort();
}
else
{
int iwkErrorNumber
= CNEwkNavionicsException.GetErrorNumber();
string swkErrorText;
CNEwkNavionicsException.MessageFormatted(swkErrorText, false);
}
}
...
m_MemDC and m_MemDC2 are correctly initialized in constructor of class.
This on OnDraw functions is called from MFC framework