I have a dialog box which will display a map on reading from the file. I have used the OnPaint() method which does the drawing. The map is redrawn when the user zoom in or zoom out for which i have used RedrawWindow(NULL,NULL,RDW_INVALIDATE | RDW_NOERASE ) as InvalidateRect(NULL) and UpdateWindow() did not work.
The problem is that the map is displayed in black color. I have used Legend class, so as to display different protions of the graph to be displayed in different color which is not working, and i have no clue for why it is happening.
I have run the program in debug mode and the appropriate color is selected for drawing, but is drawn in black. Please help.
The relevant code is below. Please let me know if there is any problem in the code.
void CMapWindowDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CDC memdc;
CBitmap *oldmap, newmap;
RECT rect;
this->GetClientRect( &rect );
memdc.CreateCompatibleDC( &dc );
newmap.CreateCompatibleBitmap( &memdc, rect.right - rect.left, rect.bottom - rect.top);
oldmap = memdc.SelectObject( &newmap );
memdc.FillSolidRect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, RGB(255, 255, 255) );
DrawClient(memdc, rect);
dc.BitBlt(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, &memdc, 0, 0, SRCCOPY);
memdc.SelectObject( oldmap );
// Do not call CDialog::OnPaint() for painting messages
}
void CMapWindowDlg:rawClient(CDC &dc, RECT &rect)
{
if( !m_DisplayFiles.GetCount() )
return;
for(int i = m_DisplayFiles.GetCount() - 1; i >= 0; i--)
{
if( !m_DisplayFiles.GetAt( m_DisplayFiles.FindIndex( i ) ).visible )
continue;
CString fileName = m_DisplayFiles.GetAt( m_DisplayFiles.FindIndex( i ) ).fileName;
if(fileName.Right( fileName.GetLength() - fileName.ReverseFind('\\') - 1 ) == "sunday.ser"
{
CString filePath = fileName.Left( fileName.ReverseFind('\\') + 1 );
CFileFind finder;
CString posFile;
CList<strPoint, strPoint&> pointList;
CList<long, long&> indexList;
long totalIndex = 0;
BOOL bWorking = finder.FindFile(filePath + "Position*.info"
while( bWorking )
{
bWorking = finder.FindNextFile();
posFile = finder.GetFilePath();
CPositionInfo posInfo;
posInfo.GetPositionIndexes( posFile, visibleMin, visibleMax, &indexList, &pointList, totalIndex );
}
CBestServing sunSer;
sunSer.DrawFile( fileName, dc, rect, &pointList, &indexList, m_Legend, visibleMin, visibleMax, Xsize, Ysize);
pointList.RemoveAll();
indexList.RemoveAll();
}
else
{
CCellCoverage cellCov;
cellCov.DrawFile( fileName, dc, rect, visibleMin, visibleMax, m_Legend, Xsize, Ysize);
}
}
}
void CCellCoverage:rawFile(CString filePath, CDC &dc, RECT &rect, strPoint &visibleMin, strPoint &visibleMax, CLegend &legend, long Xsize, long Ysize)
{
CFile filePtr;
CFileException e;
long temp1;
char temp4;
filePtr.Open(filePath.operator LPCTSTR(), CFile::modeRead | CFile::typeBinary, &e);
filePtr.Seek( sizeof(char) * 14 + sizeof(char) * 8 + sizeof(long) * 4, CFile::begin);
filePtr.Read( (void *) &noOfData, sizeof(long) );
filePtr.Seek( sizeof(char) * 14 + sizeof(char) * 8 + sizeof(long) * 4 + sizeof(long) + sizeof(unsigned char) + sizeof(char) * 20, CFile::begin);
for(long i = 0; i < noOfData; i++)
{
long X;
long Y;
strPositionStrength posData;
filePtr.Read( (void *) &temp1, sizeof(long) );
posData.point.Easting = temp1;
filePtr.Read( (void *) &temp1, sizeof(long) );
posData.point.Northing = temp1;
if(posData.point > visibleMax)
break;
if(posData.point < visibleMin)
continue;
filePtr.Read( (void *) &temp4, sizeof(char) );
posData.strength = temp4;
X = rect.left + ( rect.right - rect.left ) * ( posData.point.Easting + 10 - visibleMin.Easting ) / ( visibleMax.Easting + 10 - visibleMin.Easting );
Y = rect.top + ( rect.bottom - rect.top ) * ( posData.point.Northing - visibleMax.Northing - 10 ) / ( visibleMin.Northing - visibleMax.Northing - 10 );
COLORREF color = legend.GetLegendColor( posData.strength );
dc.FillSolidRect(X, Y, Xsize, Ysize, color);
}
filePtr.Close();
}
void CPositionInfo::GetPositionIndexes(CString file, strPoint& visibleMin, strPoint& visibleMax, CList<long, long&> *indexList, CList<strPoint, strPoint&> *pointList, long &totalIndex)
{
CFile filePtr;
CFileException e;
long temp1, headerSize, dataSize;
headerSize = sizeof(char) * 14 + sizeof(char) * 8 + sizeof(long) * 5 + sizeof(char) * 20;
dataSize = sizeof(long) * 2;
filePtr.Open(file.operator LPCTSTR(), CFile::modeRead | CFile::typeBinary, &e);
filePtr.Seek(sizeof(char) * 14 + sizeof(char) * 8, CFile::begin);
filePtr.Read( (void *) &temp1, sizeof(long) );
boundaryMin.Easting = temp1;
filePtr.Read( (void *) &temp1, sizeof(long) );
boundaryMin.Northing = temp1;
filePtr.Read( (void *) &temp1, sizeof(long) );
boundaryMax.Easting = temp1;
filePtr.Read( (void *) &temp1, sizeof(long) );
boundaryMax.Northing = temp1;
filePtr.Read( (void *) &noOfPoints, sizeof(long) );
if(visibleMin > boundaryMax || visibleMax < boundaryMin)
{
totalIndex += noOfPoints;
filePtr.Close();
return;
}
filePtr.Seek( headerSize, CFile::begin );
for(long i = 0; i < noOfPoints; i++)
{
strPoint point;
filePtr.Read( (void *) &temp1, sizeof(long) );
point.Easting = temp1;
filePtr.Read( (void *) &temp1, sizeof(long) );
point.Northing = temp1;
if( point > visibleMax )
break;
if( point < visibleMin || (point.Northing < visibleMin.Northing || point.Northing > visibleMax.Northing) )
continue;
pointList->AddTail( point );
long index = totalIndex + i;
indexList->AddTail( index );
}
totalIndex += noOfPoints;
filePtr.Close();
}
void CBestServing:rawFile(CString file, CDC& dc, RECT& rect, CList<strPoint, strPoint&> *pointList, CList<long, long&> *indexList, CLegend& legend, strPoint& visibleMin, strPoint visibleMax, long Xsize, long Ysize)
{
CFile filePtr;
CFileException e;
long headerSize, dataSize;
headerSize = sizeof(char) * 14 + sizeof(char) * 8 + sizeof(long) * 5 + sizeof(unsigned char) + sizeof(char) * 20;
dataSize = sizeof(long);
filePtr.Open(file.operator LPCTSTR(), CFile::modeRead | CFile::typeBinary, &e);
for(long i = 0; i < pointList->GetCount(); i++)
{
long X, Y;
char stg;
strPoint& point = pointList->GetAt( pointList->FindIndex( i ) );
long index = indexList->GetAt( indexList->FindIndex( i ) );
filePtr.Seek( headerSize + dataSize * index, CFile::begin);
filePtr.Read( (void *) &stg, sizeof(char) );
X = rect.left + ( rect.right - rect.left ) * ( point.Easting + 10 - visibleMin.Easting ) / ( visibleMax.Easting + 10 - visibleMin.Easting );
Y = rect.top + ( rect.bottom - rect.top ) * ( point.Northing - visibleMax.Northing - 10 ) / ( visibleMin.Northing - visibleMax.Northing - 10 );
COLORREF color = legend.GetLegendColor( stg );
dc.FillSolidRect(X, Y, Xsize, Ysize, color);
}
filePtr.Close();
}
COLORREF CLegend::GetLegendColor(char stg)
{
COLORREF color = RGB(0, 0, 0);
for(int i = 0; i < m_Legend.GetCount(); i++)
{
if( stg >= m_Legend.GetAt( m_Legend.FindIndex( i ) ).low && stg <= m_Legend.GetAt( m_Legend.FindIndex( i ) ).high )
{
color = m_Legend.GetAt( m_Legend.FindIndex( i ) ).color;
break;
}
}
return color;
}
Thanks in advance
The problem is that the map is displayed in black color. I have used Legend class, so as to display different protions of the graph to be displayed in different color which is not working, and i have no clue for why it is happening.
I have run the program in debug mode and the appropriate color is selected for drawing, but is drawn in black. Please help.
The relevant code is below. Please let me know if there is any problem in the code.
void CMapWindowDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CDC memdc;
CBitmap *oldmap, newmap;
RECT rect;
this->GetClientRect( &rect );
memdc.CreateCompatibleDC( &dc );
newmap.CreateCompatibleBitmap( &memdc, rect.right - rect.left, rect.bottom - rect.top);
oldmap = memdc.SelectObject( &newmap );
memdc.FillSolidRect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, RGB(255, 255, 255) );
DrawClient(memdc, rect);
dc.BitBlt(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, &memdc, 0, 0, SRCCOPY);
memdc.SelectObject( oldmap );
// Do not call CDialog::OnPaint() for painting messages
}
void CMapWindowDlg:rawClient(CDC &dc, RECT &rect)
{
if( !m_DisplayFiles.GetCount() )
return;
for(int i = m_DisplayFiles.GetCount() - 1; i >= 0; i--)
{
if( !m_DisplayFiles.GetAt( m_DisplayFiles.FindIndex( i ) ).visible )
continue;
CString fileName = m_DisplayFiles.GetAt( m_DisplayFiles.FindIndex( i ) ).fileName;
if(fileName.Right( fileName.GetLength() - fileName.ReverseFind('\\') - 1 ) == "sunday.ser"
{
CString filePath = fileName.Left( fileName.ReverseFind('\\') + 1 );
CFileFind finder;
CString posFile;
CList<strPoint, strPoint&> pointList;
CList<long, long&> indexList;
long totalIndex = 0;
BOOL bWorking = finder.FindFile(filePath + "Position*.info"
while( bWorking )
{
bWorking = finder.FindNextFile();
posFile = finder.GetFilePath();
CPositionInfo posInfo;
posInfo.GetPositionIndexes( posFile, visibleMin, visibleMax, &indexList, &pointList, totalIndex );
}
CBestServing sunSer;
sunSer.DrawFile( fileName, dc, rect, &pointList, &indexList, m_Legend, visibleMin, visibleMax, Xsize, Ysize);
pointList.RemoveAll();
indexList.RemoveAll();
}
else
{
CCellCoverage cellCov;
cellCov.DrawFile( fileName, dc, rect, visibleMin, visibleMax, m_Legend, Xsize, Ysize);
}
}
}
void CCellCoverage:rawFile(CString filePath, CDC &dc, RECT &rect, strPoint &visibleMin, strPoint &visibleMax, CLegend &legend, long Xsize, long Ysize)
{
CFile filePtr;
CFileException e;
long temp1;
char temp4;
filePtr.Open(filePath.operator LPCTSTR(), CFile::modeRead | CFile::typeBinary, &e);
filePtr.Seek( sizeof(char) * 14 + sizeof(char) * 8 + sizeof(long) * 4, CFile::begin);
filePtr.Read( (void *) &noOfData, sizeof(long) );
filePtr.Seek( sizeof(char) * 14 + sizeof(char) * 8 + sizeof(long) * 4 + sizeof(long) + sizeof(unsigned char) + sizeof(char) * 20, CFile::begin);
for(long i = 0; i < noOfData; i++)
{
long X;
long Y;
strPositionStrength posData;
filePtr.Read( (void *) &temp1, sizeof(long) );
posData.point.Easting = temp1;
filePtr.Read( (void *) &temp1, sizeof(long) );
posData.point.Northing = temp1;
if(posData.point > visibleMax)
break;
if(posData.point < visibleMin)
continue;
filePtr.Read( (void *) &temp4, sizeof(char) );
posData.strength = temp4;
X = rect.left + ( rect.right - rect.left ) * ( posData.point.Easting + 10 - visibleMin.Easting ) / ( visibleMax.Easting + 10 - visibleMin.Easting );
Y = rect.top + ( rect.bottom - rect.top ) * ( posData.point.Northing - visibleMax.Northing - 10 ) / ( visibleMin.Northing - visibleMax.Northing - 10 );
COLORREF color = legend.GetLegendColor( posData.strength );
dc.FillSolidRect(X, Y, Xsize, Ysize, color);
}
filePtr.Close();
}
void CPositionInfo::GetPositionIndexes(CString file, strPoint& visibleMin, strPoint& visibleMax, CList<long, long&> *indexList, CList<strPoint, strPoint&> *pointList, long &totalIndex)
{
CFile filePtr;
CFileException e;
long temp1, headerSize, dataSize;
headerSize = sizeof(char) * 14 + sizeof(char) * 8 + sizeof(long) * 5 + sizeof(char) * 20;
dataSize = sizeof(long) * 2;
filePtr.Open(file.operator LPCTSTR(), CFile::modeRead | CFile::typeBinary, &e);
filePtr.Seek(sizeof(char) * 14 + sizeof(char) * 8, CFile::begin);
filePtr.Read( (void *) &temp1, sizeof(long) );
boundaryMin.Easting = temp1;
filePtr.Read( (void *) &temp1, sizeof(long) );
boundaryMin.Northing = temp1;
filePtr.Read( (void *) &temp1, sizeof(long) );
boundaryMax.Easting = temp1;
filePtr.Read( (void *) &temp1, sizeof(long) );
boundaryMax.Northing = temp1;
filePtr.Read( (void *) &noOfPoints, sizeof(long) );
if(visibleMin > boundaryMax || visibleMax < boundaryMin)
{
totalIndex += noOfPoints;
filePtr.Close();
return;
}
filePtr.Seek( headerSize, CFile::begin );
for(long i = 0; i < noOfPoints; i++)
{
strPoint point;
filePtr.Read( (void *) &temp1, sizeof(long) );
point.Easting = temp1;
filePtr.Read( (void *) &temp1, sizeof(long) );
point.Northing = temp1;
if( point > visibleMax )
break;
if( point < visibleMin || (point.Northing < visibleMin.Northing || point.Northing > visibleMax.Northing) )
continue;
pointList->AddTail( point );
long index = totalIndex + i;
indexList->AddTail( index );
}
totalIndex += noOfPoints;
filePtr.Close();
}
void CBestServing:rawFile(CString file, CDC& dc, RECT& rect, CList<strPoint, strPoint&> *pointList, CList<long, long&> *indexList, CLegend& legend, strPoint& visibleMin, strPoint visibleMax, long Xsize, long Ysize)
{
CFile filePtr;
CFileException e;
long headerSize, dataSize;
headerSize = sizeof(char) * 14 + sizeof(char) * 8 + sizeof(long) * 5 + sizeof(unsigned char) + sizeof(char) * 20;
dataSize = sizeof(long);
filePtr.Open(file.operator LPCTSTR(), CFile::modeRead | CFile::typeBinary, &e);
for(long i = 0; i < pointList->GetCount(); i++)
{
long X, Y;
char stg;
strPoint& point = pointList->GetAt( pointList->FindIndex( i ) );
long index = indexList->GetAt( indexList->FindIndex( i ) );
filePtr.Seek( headerSize + dataSize * index, CFile::begin);
filePtr.Read( (void *) &stg, sizeof(char) );
X = rect.left + ( rect.right - rect.left ) * ( point.Easting + 10 - visibleMin.Easting ) / ( visibleMax.Easting + 10 - visibleMin.Easting );
Y = rect.top + ( rect.bottom - rect.top ) * ( point.Northing - visibleMax.Northing - 10 ) / ( visibleMin.Northing - visibleMax.Northing - 10 );
COLORREF color = legend.GetLegendColor( stg );
dc.FillSolidRect(X, Y, Xsize, Ysize, color);
}
filePtr.Close();
}
COLORREF CLegend::GetLegendColor(char stg)
{
COLORREF color = RGB(0, 0, 0);
for(int i = 0; i < m_Legend.GetCount(); i++)
{
if( stg >= m_Legend.GetAt( m_Legend.FindIndex( i ) ).low && stg <= m_Legend.GetAt( m_Legend.FindIndex( i ) ).high )
{
color = m_Legend.GetAt( m_Legend.FindIndex( i ) ).color;
break;
}
}
return color;
}
Thanks in advance