当前位置:网站首页>MFC interface development help document -- BCG how to place controls on the toolbar

MFC interface development help document -- BCG how to place controls on the toolbar

2020-11-10 10:51:59 FILA6666

BCGControlBar ("Business Components Gallery ControlBar") yes MFC expanded memory bank , Enables you to create with fully custom options ( Functional area 、 Customizable toolbar 、 Menu, etc ) And a rich set of professional design Microsoft Office and Microsoft Visual Studio Applications for GUI Control , For example, chart 、 The calendar 、 grid 、 Editor 、 Gantt chart and many other controls .

BCGControlBar The library owns 500 Many have been fully designed 、 Tested and fully documented MFC The extension class . Our components can be easily integrated into your application , And save you hundreds of development and debugging time .

 

This article will show you how to place various controls on the toolbar , Such as combo box or edit box .

for example , You want to create a "Find" Combo box , The combo box appears on the toolbar and contains the most recently used search string . The user will be able to enter a string in the combo box edit control , Then press Enter Key to search for documents , Or press Escape Key to return the focus to the main frame , The document is displayed in CEditView - derived In the view .

The following steps are "setup" Work , Handle the creation of combo box button and the processing of its commands :

1. Open application resources , Will have ID_EDIT_FIND command ID Add a new button to the desired (IDR_MAINFRAME) The toolbar , And create with the same ID New menu items for . Use ID_EDIT_FIND_COMBO command ID Put the new string “ Find the text \ nFind” Add to string table , The ID Will be used as find Combo box button command ID. Be careful ID_EDIT_FIND yes CEditView Standard commands for processing , So you don't need to implement a special handler for this command , But it needs to be for ID_EDIT_FIND_COMBO Command implementation handler .

2. from CBCGPComboBox Class derives a class , We named it CFindComboBox.

3. stay CFindComboBox Class , rewrite PreTranslateMessage Virtual member functions , This will allow you to deal with WM_KEYDOWN News and take appropriate measures . When the user presses the exit key (VK_ESCAPE) when , Returns the focus to the main frame window . When the user presses Enter key (VK_ENTER) when , Will have ID_EDIT_FIND_COMBO command ID Of WM_COMMAND The message is posted to the main frame window ( The command will be routed to the view ).

4. from CBCGPToolbarComboBoxButton Class derives a class , We named it CFindComboButton.

5. CBCGPToolbarComboBoxButton The constructor of takes three parameters : Button command ID、 Button image all and combo box styles , You should ID_EDIT_FIND_COMBO As command ID Pass on , And you can put CImageHash :: GetImageOfCommand And ID_EDIT_FIND Together to get an image index .

6. rewrite CBCGPToolbarComboBoxButton :: CreateCombo Member functions , Here you should create CFindComboBox Object and returns a pointer to it .

7. Use IMPLEMENT_SERIAL Macro makes the combo button durable , The workspace manager will automatically be in Windows The state of the load and save button in the registry .

8. Implement... In your view ID_EDIT_FIND_COMBO The handler , Use a ID_EDIT_FIND_COMBO ID Of  CBCGPToolBar::GetCommandButtons  You can retrieve all of "Find" Combo box button , Due to customization , It can be with the same command ID Multiple copies of combo box buttons of .

9. Use CBCGPToolBar::IsLastCommandFromButton To determine whether or not sent from our combo box button "Find" command , To do this, find the text and add the search string to the combo box .

You should perform the following steps , take find Put the combo box button on the toolbar :

1. In the main frame window BCGM_RESETTOOLBAR Message handler (OnToolbarReset), Note that when the toolbar is initialized ( When the application starts ), Or when the toolbar is reset during customization , The message is sent from the frame to the main frame window . In either case , All need to use "custom" find The combo box button replaces the standard toolbar button ( See step 2).

2. stay OnToolbarReset In process , Analyze the toolbar ID( It is BCGM_RESETTOOLBAR  News WPARAM). encounter IDR_MAINFRAME On the toolbar , Just use ID_EDIT_FIND And for CFindComboButton Object reference calls CBCGPToolBar::ReplaceButton. Note that you can construct... On the stack CFindComboButton object , because ReplaceButton Copy the button object and maintain the copy .

3. If you enable custom , Then realize "customize" The handler (OnViewCustomize) And create CBCGPToolbarCustomize Dialog box , You must use ID_EDIT_FIND And for CFindComboButton Object to call  CBCGPToolbarCustomize::ReplaceButton . Note that the custom dialog contains "Commands" List box "Commands" page , Users can drag and drop commands onto the toolbar . By default , The custom dialog handles the application menu and builds a list of standard toolbar buttons for each category . If not used when needed CBCGPToolbarButton - derived Button to replace the standard toolbar button , The extension function provided by the derived object will be lost .

If you are right about BCGSoft We are interested in , You can also consult directly “ Online Service ”!

版权声明
本文为[FILA6666]所创,转载请带上原文链接,感谢