Adding / removing buttons from a toolbar
Amir Shoval -- amirs@ncc.co.il Thursday, February 20, 1997 Environment: VC4.2b, Win95 Hello, In my application, I create a dynamic toolbar (based on data stored in the registry). The initial display of the toolbar is 100% OK. I also have a dialog for adding / removing buttons from that toolbar (I'm not using the Customize() method). After adding or removing buttons, the toolbar is changed correctly - it DOES contain all the buttons its supposed to. But it's frame's size does not change (I can't see the new buttons, for example). Only after I click once inside the toolbar's frame, it's size is adjusted to the correct size. This behavior is the same when the toolbar is floating or docking. Here is the sequence of actions done when adding/removing buttons from the toolbar (this is kind of pseudocode): //--------------------------------------------------------------------- ---- // Delete buttons from toolbar. //--------------------------------------------------------------------- ---- nButtons = GetToolBarCtrl().GetButtonCount(); for (nIndex = 0; nIndex < nButtons; nIndex++) GetToolBarCtrl().DeleteButton(nIndex); GetToolBarCtrl().AutoSize(); //--------------------------------------------------------------------- ---- // Delete old buttons' bitmaps. //--------------------------------------------------------------------- ---- DeleteToolBitmaps(); //--------------------------------------------------------------------- ---- // Insert buttons into toolbar (m_pTools is a pointer to an array) //--------------------------------------------------------------------- ---- nButtons = m_pTools->GetSize(); SetButtons(NULL, nButtons); for (nIndex = 0; nIndex < nButtons; nIndex++) { pTool = (*m_pTools)[nIndex]; hToolIcon = pTool->GetIcon(); //-------------------------------------------------------------------- ----- // Create a bitmap from the icon //-------------------------------------------------------------------- ----- CBitmap *pToolBitmap = new CBitmap(); <...> //-------------------------------------------------------------------- ----- // Init the button: Image, style & text. //-------------------------------------------------------------------- ----- nImageNum = GetToolBarCtrl().AddBitmap(1, pToolBitmap); ASSERT(nImageNum != -1); SetButtonInfo(nIndex, ID_TOOLS_TOOL + nIndex, GetButtonStyle(nIndex) | TBBS_BUTTON, nImageNum); _splitpath(pTool->GetPath(), szDrive, szDir, szFName, szExt); SetButtonText(nIndex, szFName); } GetToolBarCtrl().AutoSize(); Am I doing something wrong or do I have to do anything more (besides AutoSize) so the toolbar will be displayed correctly? 10x, Amir -------------------------------------------------- Amir Shoval N.C.C. ISRAEL amirs@ncc.co.il --------------------------------------------------
Mario Contestabile -- Mario_Contestabile.UOS__MTL@UOSMTL2.universal.com Thursday, February 20, 1997 >After adding or removing buttons, the toolbar is changed correctly - it >DOES contain >all the buttons its supposed to. But it's frame's size does not change >(I can't see the new >buttons, for example). Do a GetParentFrame()->RecalcLayout(); afterwards. mcontest@universal.com
Become an MFC-L member | Вернуться в корень Архива |