void ToolBar::reset(bool create) { if(create && _hSelf) { //Store current button state information TBBUTTON tempBtn; for(size_t i = 0; i < _nrCurrentButtons; i++) { ::SendMessage(_hSelf, TB_GETBUTTON, (WPARAM)i, (LPARAM)&tempBtn); _pTBB[i].fsState = tempBtn.fsState; } ::DestroyWindow(_hSelf); _hSelf = NULL; } if(!_hSelf) { _hSelf = ::CreateWindowEx( WS_EX_PALETTEWINDOW, TOOLBARCLASSNAME, TEXT(""), WS_TOOLBARSTYLE, 0, 0, 0, 0, _hParent, NULL, _hInst, 0); // Send the TB_BUTTONSTRUCTSIZE message, which is required for // backward compatibility. ::SendMessage(_hSelf, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0); ::SendMessage(_hSelf, TB_SETEXTENDEDSTYLE, 0, (LPARAM)TBSTYLE_EX_HIDECLIPPEDBUTTONS); } if (!_hSelf) { throw std::runtime_error("ToolBar::reset : CreateWindowEx() function return null"); } if (_state != TB_STANDARD) { //If non standard icons, use custom imagelists setDefaultImageList(); setHotImageList(); setDisableImageList(); } else { //Else set the internal imagelist with standard bitmaps TBADDBITMAP addbmp = {_hInst, 0}; TBADDBITMAP addbmpdyn = {0, 0}; for (size_t i = 0 ; i < _nrButtons ; i++) { addbmp.nID = _toolBarIcons.getStdIconAt(i); ::SendMessage(_hSelf, TB_ADDBITMAP, 1, (LPARAM)&addbmp); } if (_nrDynButtons > 0) { for (size_t j = 0; j < _nrDynButtons; j++) { addbmpdyn.nID = (UINT_PTR)_vDynBtnReg.at(j).hBmp; ::SendMessage(_hSelf, TB_ADDBITMAP, 1, (LPARAM)&addbmpdyn); } } } if (create) { //if the toolbar has been recreated, readd the buttons size_t nrBtnToAdd = (_state == TB_STANDARD?_nrTotalButtons:_nrButtons); _nrCurrentButtons = nrBtnToAdd; WORD btnSize = (_state == TB_LARGE?32:16); ::SendMessage(_hSelf, TB_SETBUTTONSIZE , (WPARAM)0, (LPARAM)MAKELONG (btnSize, btnSize)); ::SendMessage(_hSelf, TB_ADDBUTTONS, (WPARAM)nrBtnToAdd, (LPARAM)_pTBB); } ::SendMessage(_hSelf, TB_AUTOSIZE, 0, 0); if (_pRebar) { _rbBand.hwndChild = getHSelf(); _rbBand.cxMinChild = 0; _rbBand.cyIntegral = 1; _rbBand.cyMinChild = _rbBand.cyMaxChild = getHeight(); _rbBand.cxIdeal = getWidth(); _pRebar->reNew(REBAR_BAR_TOOLBAR, &_rbBand); } }
bool ToolBar::init(HINSTANCE hInst, HWND hPere, int iconSize, ToolBarButtonUnit *buttonUnitArray, int arraySize) { Window::init(hInst, hPere); //_pToolBarIcons = pToolBarIcons; _toolBarIcons.init(buttonUnitArray, arraySize); _toolBarIcons.create(_hInst, iconSize); _state = (iconSize < 32)?REDUCED:ENLARGED; INITCOMMONCONTROLSEX icex; icex.dwSize = sizeof(INITCOMMONCONTROLSEX); icex.dwICC = ICC_BAR_CLASSES; InitCommonControlsEx(&icex); _hSelf = ::CreateWindowEx( WS_EX_PALETTEWINDOW , TOOLBARCLASSNAME, "", WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | CCS_ADJUSTABLE | CCS_TOP | BTNS_AUTOSIZE , 0, 0, 0, 0, _hParent, NULL, _hInst, 0); if (!_hSelf) { systemMessage("System Err"); throw int(9); } // long hCur = (long)::LoadCursor(hInst, MAKEINTRESOURCE(IDC_MY_CUR)); // ::SetClassLong(_hSelf, GCL_HCURSOR, hCur); // Send the TB_BUTTONSTRUCTSIZE message, which is required for // backward compatibility. ::SendMessage(_hSelf, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0); setDefaultImageList(); setHotImageList(); setDisableImageList(); int nbElement = _toolBarIcons.getNbCommand(); _pTBB = new TBBUTTON[nbElement]; for (int i = 0, j = 0; i < nbElement ; i++) { int cmd = 0; if ((cmd = _toolBarIcons.getCommandAt(i)) != 0) { _pTBB[i].iBitmap = j++; _pTBB[i].idCommand = cmd; _pTBB[i].fsState = TBSTATE_ENABLED; _pTBB[i].fsStyle = BTNS_BUTTON; _pTBB[i].dwData = 0; _pTBB[i].iString = 0; } else { _pTBB[i].iBitmap = 0; _pTBB[i].idCommand = cmd; _pTBB[i].fsState = TBSTATE_ENABLED; _pTBB[i].fsStyle = BTNS_SEP; _pTBB[i].dwData = 0; _pTBB[i].iString = 0; } } setButtonSize(iconSize, iconSize); ::SendMessage(_hSelf, TB_ADDBUTTONS, (WPARAM)nbElement, (LPARAM)_pTBB); //::SendMessage(_hSelf, TB_LOADIMAGES, IDB_VIEW_LARGE_COLOR, reinterpret_cast<LPARAM>(HINST_COMMCTRL)); ::SendMessage(_hSelf, TB_AUTOSIZE, 0, 0); return true; }