Platform SDK Shell >> adding buttons to explorer toolbar

by Bill Rowell » Sat, 05 Mar 2005 00:52:31 GMT

If I add a bitmap to the explorer toolbar for a button doing the following:

tbab.hInst = HINST_COMMCTRL;
tbab.nID = (int)IDB_STD_SMALL_COLOR;
hr = m_pShellBrowser->SendControlMsg(FCW_TOOLBAR, TB_ADDBITMAP, 0,
(LPARAM)&tbab, &lOffsetBitmap);

Should I be able to:

Reference the same bitmap on the toolbar using TB_GETBITMAP? (I've tried
this using SendControlMsg with no luck so far)

Remove the bitmap from the toolbar?

What I'm getting as is my extension always just calls SendControlMsg with
TB_ADDBITMAP every time a new shellview is created and the toolbars are
merged. I think this is causing a resource leak I have detected in my
extension, but I'm not 100% sure. All of the MS examples I've seen do it
the way I'm doing it...they don't ever seem to clean up the bitmaps that are
added.




Platform SDK Shell >> adding buttons to explorer toolbar

by Jim Barry » Tue, 08 Mar 2005 18:22:46 GMT





Yes, this is a bug in the shell. The toolbars share the same underlying imagelists, but not the data structure that enables the toolbar to keep track of which bitmaps have already been added. Everything works properly within a single Explorer window - if you add a bitmap for a second time you get back the same offset as the first time. But when you open up another Explorer window, it forgets all about the bitmaps that were added before and so there is a leak. I cannot think of a good workaround. You can store your bitmap offset in a global variable so that you only add the bitmap once, but this won't stop the leak happening each time your DLL gets unloaded and reloaded.

--
Jim Barry, MVP for Windows SDK



Platform SDK Shell >> adding buttons to explorer toolbar

by Bill Rowell » Tue, 08 Mar 2005 23:21:00 GMT

Gotcha. Thanks for the info.

Do you know if I continually add those bitmaps to the toolbar during one
Explorer window session if I'm leaking all of those bitmap resources as
well?





Yes, this is a bug in the shell. The toolbars share the same underlying
imagelists, but not the data structure that enables the toolbar to keep
track of which bitmaps have already been added. Everything works properly
within a single Explorer window - if you add a bitmap for a second time you
get back the same offset as the first time. But when you open up another
Explorer window, it forgets all about the bitmaps that were added before and
so there is a leak. I cannot think of a good workaround. You can store your
bitmap offset in a global variable so that you only add the bitmap once, but
this won't stop the leak happening each time your DLL gets unloaded and
reloaded.

--
Jim Barry, MVP for Windows SDK




adding buttons to explorer toolbar

by Jim Barry » Wed, 09 Mar 2005 01:10:30 GMT




Like I said, it all works properly within a single Explorer window ;-) Check the offset you get back from TB_ADDBITMAP. If you don't trust that, check the image count in the image list you get back from TB_GETIMAGELIST.

--
Jim Barry, MVP for Windows SDK