Runtime dynamic toolbars
Sandeep -- sandeep@cyber-wizard.com Wednesday, February 19, 1997 Environment: NT 4.0, VC++ 4.0 Hi all, I'm facing a big problem while developing my current application. What I need to do is to take options from a dialog box which will have options of adding,deleting and changing the toolbar.In the dialog box the user will be asked to enter information such as name of the task,tool tip text,status bar text and the icon file to be attached to this particular task.Actually these bitmaps or icons represent some specific tasks. Corresponding to each task the user will choose a icon file which is to be displayed in the toolbar. Initially all these files along with their full pathnames will be in an INI file. What I need to do is dynamically create the toolbars at run time and cannot create the resource using the resource editor. any suggestions? Thanks for any help Sandeep
Jeremiah Talkar -- jtalkar@optika.com Wednesday, February 19, 1997 [Mini-digest: 2 responses] This is easy and I have done a similar thing in my application. (1) First of all you need to derive a CToolbar based class for your dynamic toolbar ( assuming that you want all the docking functionality etc. ). (2) Create another class or define a typedef to hold all the information you need for each of the dynamically added buttons. (3) In your CToolbar derived class, use a Clist<> template or an array or anything to hold pointers to the class or structure defined in (2) above. (4) Define member functions to add, remove buttons ( and their relevant information ). (5) Create a member variable for each dynamic toolbar in your application's main Frame window class. (6) In the CMainFrm::OnCreate(), create each of these toolbars using the code AppWizard generates for the standard toolbar but do not make them visible if there are no buttons yet ( Use CFrameWnd::ShowControlBar() ). (7) Whenever the user inputs information a new button, call the Addxxxxx function of your CToolbar derived class. Use the following code to actually display the button on the toolbar. If you need code to convert your icon to a bitmap, e-mail me directly. iImageIndex = ToolBarCtrl.AddBitmap( 1, &bmToolBarImage ); // Ensure that the handle to the bitmap is detached before the CBitmap // object goes out of scope. bmToolBarImage.Detach(); if( iImageIndex >= 0 ) { TBButton.iBitmap = iImageIndex; TBButton.idCommand = uiEventTypeId; TBButton.fsState = TBSTATE_ENABLED; TBButton.fsStyle = TBSTYLE_BUTTON | TBSTYLE_CHECK; TBButton.dwData = 0; TBButton.iString = NULL; fRetCode = ToolBarCtrl.AddButtons( 1, &TBButton ); } (8) Use ShowControlBar() to ensure that the toolbar is visible. (9) For tooltips, override both TTN_NEEDTEXTA and TTN_NEEDTEXTW ( refer to CFrameWnd::OnToolTipText in the WinFrm.cpp file in the MFC source directory ). (10) Finally, to get the status bar messages, override GetMessageStrings() to provide the apporpriate message. E-Mail me directly if there are any doubts. Jeremiah -----Original Message----- From: Sandeep Sent: Wednesday, February 19, 1997 12:54 PM To: mfc-l@netcom.com Subject: Runtime dynamic toolbars Environment: NT 4.0, VC++ 4.0 Hi all, I'm facing a big problem while developing my current application. What I need to do is to take options from a dialog box which will have options of adding,deleting and changing the toolbar.In the dialog box the user will be asked to enter information such as name of the task,tool tip text,status bar text and the icon file to be attached to this particular task.Actually these bitmaps or icons represent some specific tasks. Corresponding to each task the user will choose a icon file which is to be displayed in the toolbar. Initially all these files along with their full pathnames will be in an INI file. What I need to do is dynamically create the toolbars at run time and cannot create the resource using the resource editor. any suggestions? Thanks for any help Sandeep -----From: Amir ShovalHello, Why create a resource for your dynamic toolbar. If you keep the data about the toolbar's buttons (tasks) in the INI file, you can create the toolbar in the regular way, NOT load a toolbar resource, and just add the buttons with all the information (which you say that you have). This task can be accomplished using CToolBar's & CToolBarCtrl's methods. If u encounter problems, I have a code example. Amir -------------------------------------------------- Amir Shoval N.C.C. ISRAEL amirs@ncc.co.il -------------------------------------------------- >---------- >From: Sandeep[SMTP:sandeep@cyber-wizard.com] >Sent: =E9=E5=ED =F8=E1=E9=F2=E9 19 =F4=E1=F8=E5=E0=F8 1997 06:54 >To: mfc-l@netcom.com >Subject: Runtime dynamic toolbars > >Environment: NT 4.0, VC++ 4.0 > >Hi all, > >I'm facing a big problem while developing my current application. What = I >need to do is to take options from a dialog box which will have options >of adding,deleting and changing the toolbar.In the dialog box the user >will be asked to enter information such as name of the task,tool tip >text,status bar text and the icon file to be attached to this = particular >task.Actually these bitmaps or icons represent some specific tasks. >Corresponding to each task the user will choose a icon file which is = to >be displayed in the toolbar.=20 >Initially all these files along with their full pathnames will be in = an >INI file.=20 > >What I need to do is dynamically create the toolbars at run time and >cannot create the resource using the resource editor. > >any suggestions? > >Thanks for any help > >Sandeep >
Ho Pham -- hop@allensysgroup.com Thursday, February 20, 1997 Sandeep wrote: > > Environment: NT 4.0, VC++ 4.0 I see that this dynamic toolbars subject had come up alot in the past. Having played with dynamic toolbars recently here is what I did: - Create 16x15 bitmaps for all of the toolbar buttons that you will need and store them into the resource file. - At run time, create an empty toolbar. Then for each button that you need do: toolbar->AddBitmaps (1, IDB_bitmapxxx); Create a TBBUTTON struct, set the button index, command ID, style etc... toolbar->AddButtons (1, &TBBUTTON); =============== Ho Pham hop@allensysgroup.com =============== > > Hi all, > > I'm facing a big problem while developing my current application. What I > need to do is to take options from a dialog box which will have options > of adding,deleting and changing the toolbar.In the dialog box the user > will be asked to enter information such as name of the task,tool tip > text,status bar text and the icon file to be attached to this particular > task.Actually these bitmaps or icons represent some specific tasks. > Corresponding to each task the user will choose a icon file which is to > be displayed in the toolbar. > Initially all these files along with their full pathnames will be in an > INI file. > > What I need to do is dynamically create the toolbars at run time and > cannot create the resource using the resource editor. > > any suggestions? > > Thanks for any help > > Sandeep
Dave Kolb -- sasdxk@wnt.sas.com Thursday, February 20, 1997 [Mini-digest: 2 responses] Also, you might want to investigate Stingray Software's Objective Toolkit (see http://www.stingsoft.com) that has some prety neat toolbar support (which is still beta though I believe even though OT itself is production). Dave Kolb SAS Institute >-----Original Message----- >From: hop@allensysgroup.com [SMTP:hop@allensysgroup.com] >Sent: Thursday, February 20, 1997 7:46 AM >To: mfc-l@netcom.com >Subject: Re: Runtime dynamic toolbars > >Sandeep wrote: >> >> Environment: NT 4.0, VC++ 4.0 > >I see that this dynamic toolbars subject had come up alot in the past. Having >played with dynamic toolbars recently here is what I did: > > - Create 16x15 bitmaps for all of the toolbar buttons that you will > need and store them into the resource file. > - At run time, create an empty toolbar. Then for each button that > you need do: > toolbar->AddBitmaps (1, IDB_bitmapxxx); > Create a TBBUTTON struct, set the button index, command ID, style >etc... > toolbar->AddButtons (1, &TBBUTTON); > >=============== >Ho Pham >hop@allensysgroup.com >=============== >> >> Hi all, >> >> I'm facing a big problem while developing my current application. What I >> need to do is to take options from a dialog box which will have options >> of adding,deleting and changing the toolbar.In the dialog box the user >> will be asked to enter information such as name of the task,tool tip >> text,status bar text and the icon file to be attached to this particular >> task.Actually these bitmaps or icons represent some specific tasks. >> Corresponding to each task the user will choose a icon file which is to >> be displayed in the toolbar. >> Initially all these files along with their full pathnames will be in an >> INI file. >> >> What I need to do is dynamically create the toolbars at run time and >> cannot create the resource using the resource editor. >> >> any suggestions? >> >> Thanks for any help >> >> Sandeep -----From: hou@tfn.com (Bing Hou) To do what you desire, you need to take care of the following things. 1. Dynamically change the number of buttons on the toolbar. 2. Assign IDs for each button. 3. Set bitmap for the toolbar. 4. Handling UI update. 5. Handling commands. The following code illustrates the things to do: // The first thing you do is to create a whole bunch of IDs, more than // what you could possible use static NEAR UINT tbIDArray[MAX_NUM] = { FirstID, ..., LastID }; BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd) ... ON_COMMAND_RANGE(FirstID, LastID, OnToolbarCmd) ON_UPDATE_COMMAND_UI_RANGE(FirstID, LastID, OnUpdateToolBar) ... END_MESSAGE_MAP() int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { ... if (!m_wndToolBar.Create(this)) // || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create } // create some initial buttons m_wndToolBar.SetButtons(tbIDArray, SomeNumber); // set buttons style for each button UINT id, style; int image; m_wndToolBar.GetButtonInfo(0, id, style, image); m_wndToolBar.SetButtonInfo(0, id, style | TBBS_BUTTON, image); // this is a button, optional, they're buttons by birth m_wndToolBar.SetButtonInfo(1, 0, TBBS_SEPARATOR, 0); // this is a separator ... // do for other buttons // create a bitmap for the whole toolbar. you may have some work of // your own here, 'couse you need to create a bitmap the right size // in memeory. HBITMAP bitmap; ... // create the bitmap m_wndToolBar.SetBitmap(bitmap); // set button size, optional, depending on your implementation CSize buttonSize(32+7, 32+7), imageSize(32, 32); m_wndToolBar.SetSizes(buttonSize, imageSize); ... } // Use this function to change toolbar's appearance dynamically // void CMainFrame::OnChangeToolbar() { // I used static command IDs here, you could change them if you like // SetButtons will delete all buttons previously on the toolbar m_wndToolBar.SetButtons(tbIDArray, SomeNumberOtherThanTheOriginal); // repeat the steps in the OnCreate function(shown above) ... } // Use this function to update command UI for toolbar // void CMainFrame::OnUpdateToolBar(CCmdUI* pUI) { // TODO } // Use this function to handle commands generated by the toolbar // void CMainFrame::OnToolbarCmd(UINT nID) { // TODO } ______________________________ Reply Separator _________________________________ Subject: Runtime dynamic toolbars Author: Sandeepat Internet Date: 2/19/97 12:54 PM Environment: NT 4.0, VC++ 4.0 Hi all, I'm facing a big problem while developing my current application. What I need to do is to take options from a dialog box which will have options of adding,deleting and changing the toolbar.In the dialog box the user will be asked to enter information such as name of the task,tool tip text,status bar text and the icon file to be attached to this particular task.Actually these bitmaps or icons represent some specific tasks. Corresponding to each task the user will choose a icon file which is to be displayed in the toolbar. Initially all these files along with their full pathnames will be in an INI file. What I need to do is dynamically create the toolbars at run time and cannot create the resource using the resource editor. any suggestions? Thanks for any help Sandeep
Become an MFC-L member | Вернуться в корень Архива |