+ m_hBitmap = (WXHBITMAP)hBitmap;
+
+ // Now blit all the tools onto this bitmap
+ HDC memoryDC = ::CreateCompatibleDC(NULL);
+ HBITMAP oldBitmap = (HBITMAP) ::SelectObject(memoryDC, hBitmap);
+
+ HDC memoryDC2 = ::CreateCompatibleDC(NULL);
+
+ // the button position
+ wxCoord x = 0;
+
+ // the number of buttons (not separators)
+ int nButtons = 0;
+
+ wxToolBarToolsList::Node *node = m_tools.GetFirst();
+ while ( node )
+ {
+ wxToolBarToolBase *tool = node->GetData();
+ if ( tool->IsButton() )
+ {
+ HBITMAP hbmp = GetHbitmapOf(tool->GetBitmap1());
+ if ( hbmp )
+ {
+ HBITMAP oldBitmap2 = (HBITMAP)::SelectObject(memoryDC2, hbmp);
+ if ( !BitBlt(memoryDC, x, 0, m_defaultWidth, m_defaultHeight,
+ memoryDC2, 0, 0, SRCCOPY) )
+ {
+ wxLogLastError("BitBlt");
+ }
+
+ ::SelectObject(memoryDC2, oldBitmap2);
+ }
+ else
+ {
+ wxFAIL_MSG( _T("invalid tool button bitmap") );
+ }
+
+ // still inc width and number of buttons because otherwise the
+ // subsequent buttons will all be shifted which is rather confusing
+ // (and like this you'd see immediately which bitmap was bad)
+ x += m_defaultWidth;
+ nButtons++;
+ }
+
+ node = node->GetNext();
+ }
+
+ ::SelectObject(memoryDC, oldBitmap);
+ ::DeleteDC(memoryDC);
+ ::DeleteDC(memoryDC2);
+
+ // Map to system colours
+ wxMapBitmap(hBitmap, totalBitmapWidth, totalBitmapHeight);
+
+ int bitmapId = 0;
+
+ bool addBitmap = TRUE;
+
+ if ( oldToolBarBitmap )
+ {
+#ifdef TB_REPLACEBITMAP
+ if ( wxTheApp->GetComCtl32Version() >= 400 )
+ {
+ TBREPLACEBITMAP replaceBitmap;
+ replaceBitmap.hInstOld = NULL;
+ replaceBitmap.hInstNew = NULL;
+ replaceBitmap.nIDOld = (UINT) oldToolBarBitmap;
+ replaceBitmap.nIDNew = (UINT) hBitmap;
+ replaceBitmap.nButtons = nButtons;
+ if ( !::SendMessage(GetHwnd(), TB_REPLACEBITMAP,
+ 0, (LPARAM) &replaceBitmap) )
+ {
+ wxFAIL_MSG(wxT("Could not replace the old bitmap"));
+ }
+
+ ::DeleteObject(oldToolBarBitmap);
+
+ // already done
+ addBitmap = FALSE;
+ }
+ else
+#endif // TB_REPLACEBITMAP
+ {
+ // we can't replace the old bitmap, so we will add another one
+ // (awfully inefficient, but what else to do?) and shift the bitmap
+ // indices accordingly
+ addBitmap = TRUE;
+
+ bitmapId = m_nButtons;
+ }
+
+ // Now delete all the buttons
+ for ( size_t pos = 0; pos < m_nButtons; pos++ )
+ {
+ if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, 0, 0) )
+ {
+ wxLogLastError("TB_DELETEBUTTON");
+ }
+ }