Addition of combination box controls in toolbar by MFC programming

zhaozj2021-02-11  261

---- Windows UI technology has always been the technique of programming staff, especially user interface programming staff. Obviously, a beautiful interface will leave a deep impression on the user. The popularity of the Windows operating system is also the continuous innovation and improvement of its user interface. The launch of every new software such as Office 97, Visual Studio 97, Outlook, IE can give people a new feel. In particular, these software tools are very beautiful, such as 3D-form toolbars, flight TIPS, these tips are both attractive, and it is convenient for users. We know that the standard toolbar provided by Visual C is basically only only simple, such as documentation, storage, and some editing function buttons, and Visual C itself is very rich, especially in the toolbar. The control is very convenient. In fact, using the MFC programming to add some interesting controls in the toolbar or easier, let's talk about how to use the MFC programming to increase the combo box control in the toolbar.

---- 1 Creating the AppWizard project file is set to Toolbar and use the system default settings.

---- 2 Open the resource editor, select the toolbar, add a button in the toolbar, set the button ID to ID_MY_COMBO_BOX. Move this button to make the button at an appropriate location.

---- 3 Delicate a new class CMYTOOLBAR from CToolbar, add a member variable m_wndmycomboBOX in the CMYTOOLBAR class, the code is as follows:

Class CMYTOOLBAR: PUBLIC CTOOLBAR

{

PUBLIC:

CCOMBOBOX M_WNDMYCOMBOBOX;

}

---- Note To place the code in the "#ndif //_ver> 1000" statement in the project file mainframe.h, class CMAINFRAME definitions.

---- 4 Replace the CToolBar variable M_WndToolbar in the project file mainframe.h instead with the CMYTOOLBAR variable m_wndtoolbar. At the same time, the function creteMycombotoolbar () declaration is added. code show as below:

protected: // control bar Embedded Member

CSTATUSBAR M_WNDSTATUSBAR;

CMYTOOLBAR M_WNDTOOLBAR;

INT CREATEMYCOTOOLBAR ();

---- 5 Call the function createmyToolbar before the oncreate () function returns the statement in the engineering file mainframe.cpp; the code is as follows:

IF (! CREATEMYCOMBOTOOLBAR ())

MessageBox ("Create My Combo Toolbar Failure);

---- 6 Open the resource header files in text, add a control ID as follows, pay attention to the ID value of this control not to repeat with other control or resources:

#define IDC_MY_COMBO 1111

---- 7 In the project file mainframe.cpp, add the function cretemytoolbar (); the code is as follows:

INT mainframe :: createmytoolbar ()

{

#define combo_box_width 80 // The Width of The Combo Box

// set up The ComboBox Control as a select box

// first Get the index of the button

Position in the Toolbar

INT INDEX = 0;

CRECR RECT;

While (m_wndtoolbar.getitemid (index)! = ID_MY_COMBO_BOX) INDEX ;

// Next Convert That Button to a

SEPERATOR AND GET ITS Position

m_wndtoolbar.setButtonInfo (INDEX,

ID_MY_COMBO_BOX, TBBS_SEPARATOR, COMBO_BOX_WIDTH);

M_WndToolBar.getItemRect (Index, & Re);

// Expand the Rectangle to Allow THE

Combo Box Room To Drop Down

RECT.TOP = 2;

Rect.bottom = 200;

// .create the Combo Box and show it

IF (! m_wndtoolbar.m_ wndmycomboBox.create

WS_CHILD | WS_VISIBLE | CBS_AUTOHSCROLL |

CBS_DropDownList | CBS_HASSTRINGS,

RECT, & M_WNDTOOLBAR, IDC_MY_COMBO))

{

Trace0 ("Failed to Create Combo-Box / N");

Return False;

}

m_wndtoolbar.m_wndmycomboBox.showWindow; Sw_show;

// adding to the combo box

m_wndtoolbar.m_wndmycomboBox.Addstring ("Fisrt Select");

m_wndtoolbar.m_wndmycomboBOX.Addstring ("Second Select");

m_wndtoolbar.m_wndmycomboBox.addstring ("third select");

m_wndtoolbar.m_wndmycomboBox.Addstring ("Four Select");

m_wndtoolbar.m_wndmycomboBox.Addstring ("fiffh select");

M_WndtoolBar.m_WndmycomboBox.Setcursel (0);

}

---- Compiling and run the application, you will find that there is a combination of a combination box control in the toolbar. See the figure below (omitted).

---- From the above routine, it can be seen that the new control is added to the toolbar, and the key is to rewrite the oncreate () function of the main frame. To master this, you can add a variety of controls in the toolbar, such as adding an Infinite Infinite Input (RADIO) control, check box control, etc. Interested readers can try to deepen understanding.

转载请注明原文地址:https://www.9cbs.com/read-4060.html

New Post(0)