Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redrawing a dialog box

Status
Not open for further replies.

raochetan

Programmer
Aug 20, 2001
62
IN
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 drawn only when the dialog box is created. I want the map to be redrawn when the user zoom in or zoom out. Though it calls the OnPaint() method again, but there is no effect on the screen. I do not know what is the reason behind it. I have used PostMessage(WM_PAINT) to redraw the dialog box.

Can anyone suggest the reason and what way i can redraw the dialog box.

Thanks in advance.

raochetan
 
Try to use:

UpdateWindow
or
InvalidateRect(NULL);

HTH,

PS:I don't know if you are using MFC or not. s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
I tried both of them. It does not work. If i use InvalidateRect(NULL), the dialog box windows changes to its default color. Also i am using MFC. 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::DrawClient(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;

CCellCoverage cellCov;
cellCov.DrawFile( fileName, dc, rect, visibleMin, visibleMax, m_Legend, Xsize, Ysize);
}
}

void CCellCoverage::DrawFile(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();
}

Thanks in advance

raochetan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top