ID: Q186151
The information in this article applies to:
When you implement the view portion of a shell namespace extension that will be run on Internet Explorer 4.0x with the desktop update, you can supply separate hot and normal images that will be displayed in Internet Explorer's toolbar. Supporting regular images where the hot and normal image is the same is fairly simple to implement. Supporting separate hot and normal images is more complicated, but you can do it.
To support separate hot and normal toolbar images, you cannot use the TB_ADDBITMAP message with IShellBrowser::SendControlMsg. You have to get the Internet Explorer toolbar's hot and normal image lists using TB_GETHOTIMAGELIST and TB_GETIMAGELIST with SendControlMsg. You then need to add your images to the toolbar's image lists using the image list functions.
You also need to make sure your images are the same size as those used by the Internet Explorer's toolbar. When adding to the Internet Explorer toolbar's image list, your images must be the exact same size as those in the toolbar. For example, if your images are 16 x 16 pixels and the toolbar's images are 32 x 32 pixels, you need to draw your images centered in a 32 x 32 image and then add the images to the toolbar. The code below shows how to do this.
//Define this as whatever RGB value you used for your transparent color.
#define TRANSPARENT_COLOR (RGB(192, 192, 192))
LRESULT lResult = 0;
HIMAGELIST himlHot,
himlNormal;
//Get the Internet Explorer toolbar's hot image list.
m_pShellBrowser->SendControlMsg( FCW_TOOLBAR,
TB_GETHOTIMAGELIST,
0,
0,
(LRESULT*)&himlHot);
//Get the Internet Explorer toolbar's normal image list.
m_pShellBrowser->SendControlMsg( FCW_TOOLBAR,
TB_GETIMAGELIST,
0,
0,
(LRESULT*)&himlNormal);
if(himlNormal && himlHot)
{
HIMAGELIST himlAddNorm,
himlAddHot;
//Create an image list from your normal images.
himlAddNorm = ImageList_LoadImage( g_hInst,
MAKEINTRESOURCE(IDB_TOOLS_NORM),
16,
0,
TRANSPARENT_COLOR,
IMAGE_BITMAP,
LR_DEFAULTCOLOR);
if(himlAddNorm)
{
//Merge the normal images.
lResult = ResizeAndMergeImages( himlNormal,
himlAddNorm,
TRANSPARENT_COLOR);
ImageList_Destroy(himlAddNorm);
}
//Create an image list from your hot images.
himlAddHot = ImageList_LoadImage( g_hInst,
MAKEINTRESOURCE(IDB_TOOLS_HOT),
16,
0,
TRANSPARENT_COLOR,
IMAGE_BITMAP,
LR_DEFAULTCOLOR);
if(himlAddHot)
{
//Merge the hot images.
ResizeAndMergeImages(himlHot, himlAddHot, TRANSPARENT_COLOR);
ImageList_Destroy(himlAddHot);
}
}
else
{
TBADDBITMAP tbab;
tbab.hInst = g_hInst;
tbab.nID = (int)IDB_TOOLS_NORM;
m_pShellBrowser->SendControlMsg( FCW_TOOLBAR,
TB_ADDBITMAP,
2,
(LPARAM)&tbab,
&lResult);
}
/*********************************************************************
ResizeAndMergeImages()
*********************************************************************/
int ResizeAndMergeImages( HIMAGELIST himlDest,
HIMAGELIST himlSrc,
COLORREF clrTransparent)
{
int nReturn = -1;
int cxDest,
cyDest,
cxSrc,
cySrc,
nImages;
HDC hdcScreen;
ImageList_GetIconSize(himlDest, &cxDest, &cyDest);
ImageList_GetIconSize(himlSrc, &cxSrc, &cySrc);
nImages = ImageList_GetImageCount(himlSrc);
hdcScreen = GetDC(NULL);
if(hdcScreen)
{
HDC hdc;
hdc = CreateCompatibleDC(hdcScreen);
if(hdc)
{
RECT rc;
HBITMAP hbm;
rc.left = 0;
rc.top = 0;
rc.right = cxDest;
rc.bottom = cyDest;
hbm = CreateCompatibleBitmap(hdcScreen, rc.right, rc.bottom);
if(hbm)
{
HBRUSH hbr;
hbr = CreateSolidBrush(clrTransparent);
if(hbr)
{
int i,
dx,
dy;
dx = (cxDest/2) - (cxSrc/2);
dy = (cyDest/2) - (cySrc/2);
//draw each image into the destination
for(i = 0; i < nImages; i++)
{
HBITMAP hbmTemp;
int n;
hbmTemp = (HBITMAP)SelectObject(hdc, hbm);
//fill the image with the transparent color
FillRect(hdc, &rc, hbr);
ImageList_Draw( himlSrc,
i,
hdc,
dx,
dy,
ILD_NORMAL);
SelectObject(hdc, hbmTemp);
n = ImageList_AddMasked(himlDest, hbm, clrTransparent);
if(-1 == nReturn)
nReturn = n;
}
DeleteObject(hbr);
}
}
DeleteDC(hdc);
}
ReleaseDC(NULL, hdcScreen);
}
return nReturn;
}
Additional query words:
Keywords : kbcode kbExtension kbNameSpace kbNTOS400 kbWinOS2000 kbWinOS95 kbWinOS98 kbGrpShell
Issue type : kbhowto
Last Reviewed: December 25, 1998