Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Converting and Icon to a Bitmap

50 views
Skip to first unread message

Ian Long

unread,
Nov 18, 1997, 3:00:00 AM11/18/97
to

Does anyone have an algorithm that converts an icon to a bitmap?
I don't mean a utility, but code that demonstrates how to do it.
For example, I want to extract an icon from a file (easy to do)
and convert that to a BITMAP.

Any help is appreciated,
Ian


Rashed Bohra

unread,
Nov 19, 1997, 3:00:00 AM11/19/97
to
To convert Icon to Bitmap

CBitmap* iconToBitmap( CWnd *pWnd, HICON hIcon, BOOL bLarge)
{
CPaintDC dc(pWnd);
CDC dcMem32, dcMem;

ASSERT(dcMem32.CreateCompatibleDC( &dc));
ASSERT(dcMem.CreateCompatibleDC( &dc));

CBitmap bitmap32;
CBitmap *pBitmap = new CBitmap;

ASSERT( pBitmap != NULL);
if ( pBitmap == NULL )
return NULL;

int width, height;

if ( bLarge )
{
width = 32;
height = 30;
}
else
{
width = 16;
height = 15;
}


bitmap32.CreateCompatibleBitmap( &dc, 32, 32);
CBitmap* pOldBitmap32 = dcMem32.SelectObject( &bitmap32);

pBitmap->CreateCompatibleBitmap( &dc, width, height);
CBitmap* pOldBitmap = dcMem.SelectObject( pBitmap);

ASSERT(dcMem32.DrawIcon( 0, 0, hIcon));
ASSERT(dcMem.StretchBlt( 0, 0, width, height, &dcMem32, 0, 0,
32,
32,SRCCOPY));

dcMem32.SelectObject( bitmap32);
dcMem.SelectObject( pOldBitmap);

return pBitmap;
}

I hope it is of help.

Rashed
ras...@astratek.com

0 new messages