MapWindow 4 - ActiveX Control Programming : MapWindow Discussion Forum
hello all I find when call the function UDPointType, the GDI object will increase (because i will change the image with the map ExtentsChanged,so i call the UDPointType function frequently) . i find up the source code in MapWinGIS.ocx. the function define as follows: in the s
when call the function UDPointType, the GDI object will increase
Posted by:
petera ()
Date: September 27, 2010 11:57PM
hello all
I find when call the function UDPointType, the GDI object will increase (because i will change the image with the map ExtentsChanged,so i call the UDPointType function frequently) . i find up the source code in MapWinGIS.ocx. the function define as follows: in the source code i find GetDC but not ReleaseDC.
thanks
I find when call the function UDPointType, the GDI object will increase (because i will change the image with the map ExtentsChanged,so i call the UDPointType function frequently) . i find up the source code in MapWinGIS.ocx. the function define as follows: in the source code i find GetDC but not ReleaseDC.
void CMapView::SetUDPointType(long LayerHandle, LPDISPATCH newValue) { Layer * l = get_ShapefileLayer(LayerHandle); if (l) { IImage * iimg = NULL; newValue->QueryInterface( IID_IImage, (void**)&iimg ); if( iimg != NULL ) { ShapeLayerInfo * sli = (ShapeLayerInfo*)l->addInfo; if( sli->udPointType != NULL ) sli->udPointType->Release(); sli->udPointType = iimg; if( sli->udDC != NULL ) sli->udDC->DeleteDC(); sli->udDC=NULL; iimg->get_Width(&(sli->udPointTypeWidth)); iimg->get_Height(&(sli->udPointTypeHeight)); if( sli->udPointTypeWidth > 0 && sli->udPointTypeHeight > 0 ) { CBitmap * bmp = new CBitmap(); bmp->CreateDiscardableBitmap(GetDC(),sli->udPointTypeWidth,sli->udPointTypeHeight); sli->udDC = new CDC(); sli->udDC->CreateCompatibleDC(GetDC()); sli->udDC->SelectObject(bmp); long pad=sli->udPointTypeWidth*24; pad%=32; if(pad!=0) { pad=32-pad; pad/=8; } if( sli->udPointTypeImage != NULL ) delete [] sli->udPointTypeImage; sli->udPointTypeImage = new unsigned char[(sli->udPointTypeWidth*3+pad)*sli->udPointTypeHeight]; long rowLength = sli->udPointTypeWidth*3 + pad; VARIANT_BOOL useImageTransparencyColor = FALSE; iimg->get_UseTransparencyColor(&useImageTransparencyColor); OLE_COLOR imageTransparencyColor = RGB(0,0,0); iimg->get_TransparencyColor(&imageTransparencyColor); sli->udTransColor=imageTransparencyColor; register int j, i; for( j = 0; j < sli->udPointTypeHeight; j++ ) { long * row = new long[sli->udPointTypeWidth+1]; VARIANT_BOOL retval; iimg->GetRow( j, row, &retval ); for( i = 0; i < sli->udPointTypeWidth; i++ ) { sli->udPointTypeImage[(sli->udPointTypeHeight-j-1)*rowLength+i*3] = GetBValue( row ); sli->udPointTypeImage[(sli->udPointTypeHeight-j-1)*rowLength+i*3+1] = GetGValue( row ); sli->udPointTypeImage[(sli->udPointTypeHeight-j-1)*rowLength+i*3+2] = GetRValue( row ); } if( row != NULL ) delete [] row; } BITMAPINFO bif; BITMAPINFOHEADER bih; bih.biBitCount=24; bih.biWidth=sli->udPointTypeWidth; bih.biHeight=sli->udPointTypeHeight; bih.biPlanes=1; bih.biSize=sizeof(BITMAPINFOHEADER); bih.biCompression=0; bih.biXPelsPerMeter=0; bih.biYPelsPerMeter=0; bih.biClrUsed=0; bih.biClrImportant=0; bih.biSizeImage=(sli->udPointTypeWidth*3+pad)*sli->udPointTypeHeight; bif.bmiHeader = bih; SetDIBitsToDevice( sli->udDC->m_hDC,0,0,sli->udPointTypeWidth,sli->udPointTypeHeight, 0,0,0,sli->udPointTypeHeight,sli->udPointTypeImage, &bif, DIB_RGB_COLORS ); } else { if( sli->udPointTypeImage != NULL ) delete [] sli->udPointTypeImage; sli->udPointTypeImage = NULL; sli->udPointTypeWidth = 0; sli->udPointTypeHeight = 0; } } else ErrorMessage(tkINTERFACE_NOT_SUPPORTED); } }
thanks
Re: when call the function UDPointType, the GDI object will increase
Posted by:
Robin Liu ()
Date: October 08, 2010 12:43AM
I'm also confused by the codes.
I think ReleaseDC is necessary for GetDC.
And maybe "delete sli->udDC;" is also needed for "sli->udDC = new CDC();".
Besides, I found some other similar strange codes:
virtual ~ShapeLayerInfo()
{
...
...
if( udDC )
{ CBitmap * newbmp = new CBitmap();
CBitmap * bmp = udDC->SelectObject(newbmp);
if( bmp )
bmp->DeleteObject();
udDC->DeleteDC();
}
}
The above codes look not so good.
"delete bmp;" and "delete udDC" are also needed here.
And then, where will newbmp go?
I hope they are not bugs.
Edited 1 time(s). Last edit at 10/08/2010 12:45AM by Robin Liu.
I think ReleaseDC is necessary for GetDC.
And maybe "delete sli->udDC;" is also needed for "sli->udDC = new CDC();".
Besides, I found some other similar strange codes:
virtual ~ShapeLayerInfo()
{
...
...
if( udDC )
{ CBitmap * newbmp = new CBitmap();
CBitmap * bmp = udDC->SelectObject(newbmp);
if( bmp )
bmp->DeleteObject();
udDC->DeleteDC();
}
}
The above codes look not so good.
"delete bmp;" and "delete udDC" are also needed here.
And then, where will newbmp go?
I hope they are not bugs.
Edited 1 time(s). Last edit at 10/08/2010 12:45AM by Robin Liu.
Sorry, only registered users may post in this forum.


