CIPAddressCtrl background image

CIPAddressCtrl background image

Post by mfc » Tue, 29 Jun 2010 23:09:48


how is it possible to add a background image to a CIPAddressCtrl
control generated by the resource editor?

I`ve written my own subclass (CImageIpAddress), where I can change the
textcolor as well as the text-background-color in the OnCtlColor

Moreover I integrated a OnPaint() method where the background-image
should be created - but it failed... At the moment only the points
between the edit control fields are gone....

CImageList m_ImageList;
BITMAP m_bitmap;
CRect m_rectBtn;
BOOL m_bLoaded;

void CImageIpAddress::OnPaint()
CDC *pDC = GetDC();

m_ImageList.DrawIndirect(pDC ,
CPoint( m_rectBtn.left, ),
CSize( m_bitmap.bmWidth , m_bitmap.bmHeight ),
CPoint( 0 , 0 ) ,


And here`s the function to load the image.

void CImageIpAddress::SetIpAddrImg(UINT uiImage)
CBitmap bitmapImage;

if( bitmapImage.LoadBitmap( uiImage ) )
bitmapImage.GetObject( sizeof( m_bitmap ) , &m_bitmap ); =0;m_rectBtn.left =0;
m_rectBtn.right = m_bitmap.bmWidth; m_rectBtn.bottom

if( m_ImageList.Create( m_bitmap.bmWidth ,
m_bitmap.bmHeight ,ILC_COLORDDB,1 ,2) )
m_ImageList.Add( &bitmapImage ,&bitmapImage);
m_bLoaded = TRUE;

Maybe someone could give me some hints to integrate a background image
to this control. On other controls this method is working.

best regards


CIPAddressCtrl background image

Post by Joseph M. » Thu, 08 Jul 2010 05:34:38

I think you are pursuing a Really Bad Design Path here. There are some things which are
simply not worth doing at all, and one of them is trying to put fancy images as
backgrounds in controls. Cute as hell, but utterly pointless, and nearly impossible to
get right.

Not worth the effort.

Joseph M. Newcomer [MVP]
MVP Tips: