How to add a plane drop-down control on the toolbar

zhaozj2021-02-17  48

How to add a flat drop-down control on the toolbar Li Jinfan

2002/11/25

People who have used WordXP know that her interface is refreshing. Especially her menus and tools can be really cool. There are also many people in the Internet to mimic her, including a lot of software companies. Her appearance makes the software community a fashion style of the XP interface. There is no more nonsense, the words retired, and I will tell you step by step by step.

Step 1: New a single document project

Step 2: In the resource editor, add a tool item. There is no content in it, the resources are named id_tool_zoom. Oh, what is the relationship between the new tool item and my drop-down control? Of course, it has a relationship, because the pull-down control is displayed in this position.

Step 3: Deriven new category, derive from CToolbar, class name is CMAINTOOLBAR. How to derive it, I only prompt you, menu INSERT-> New Class .... Selected generic classes in Class Type, if you don't choose ... you try it.

Step 4: Since we have a drop-down box, you have to declare a CCOMBOBOX object in CMAINTOOLBAR, the declaration is as follows:

PUBLIC:

CCOMBOBOX M_WNDZOOM;

Step 5: Use the new class instead of the old class. Before replacing, you have to include the new class's declaration file, on the mainfrm.h file, plus this sentence #include "maintoolbar.h". Find ctoolbar m_wndtoolbar; replace CToolbar with CMAintoolbar.

Step 6: At the end of the CMAINFRM's oncreate function (of course before return 0), add the following code:

INT INDEX = 0;

RECT;

/ / Find the specified tool item

While (m_wndtoolbar.getitemid (index)! = ID_TOOL_ZOOM)

INDEX ;

/ / Set the width of the specified tool item and get the new area 80 is the width

M_WndToolBar.SetButTonInfo (INDEX, ID_TOOL_ZOOM, TBBS_SEPARATOR, 80);

M_WndToolBar.getItemRect (Index, & Re);

// Set location

RECT.TOP = 2;

Rect.bottom = 200;

// Create and display control

IF (! m_wndtoolbar.m_wndzoom.create (ws_child | ws_visible | CBS_AUTOHSCROLL1 | CBS_DROPDOWNLIST | CBS_HASSTRINGS, RECT,

& m_wndtoolbar, ID_tool_zoom))

{

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

Return False;

}

m_wndtoolbar.m_wndzoom.showwindow (sw_show);

// Fill content

M_WndtoolBar.m_Wndzoom.Addstring ("25%");

M_WndtoolBar.m_Wndzoom.Addstring ("50%");

M_WndtoolBar.m_Wndzoom.Addstring ("75%");

M_WndtoolBar.m_Wndzoom.Addstring ("100%");

m_wndtoolbar.m_wndzoom.Addstring ("125%");

m_wndtoolbar.m_wndzoom.addstring ("150%"); m_wndtoolbar.m_wndzoom.Addstring ("175%");

m_wndtoolbar.m_wndzoom.Addstring ("200%");

// Select the default item

m_wndtoolbar.m_wndzoom.Setcurseel (3);

Add good, run it over again. Oh, it can really. However, there are three problems that need to be solved. 1. The tool bar is not high enough. Two: The following box is not a flat control. Three: How to deal with the message. Below I solve one by one:

Question 1: The tool bar is not high enough

Solve especially easy, enter the resource manager, open the tool. Just find a tool item and set its height property to 20. Such a toolbar increases.

Question 2: The following box is not a flat control

This is also easy to solve, and you will use the class of others. I am using Kirk Stowell's cflatcomboBox. The sample program already includes this class. Add FLATCOMBOBOX.H and FLATCOMBOX.CPP files to projects with projectàadd to projectàfile ... Then in the maintoolbar.h, the CFLATCOMBOX class included, of course, using #include "flatcomboBox.h". Finally, use the CFLATCOMBOBOX class instead of the CCOMBOBOX class.

Re-compile, run again, is it flat? J

Question 3: How to deal with messages

Yes, until now. This control can only be seen, can not be used, what is meaningful. So we have to deal with his news and let him live. We can't expect ClassWizard to help us, because ClassWizard can't see this news, so everything has to rely on our own.

On the CMAINFRM class, we have to add an AFX_MSG void onselectzoomoomed (); function in protected; function. Then go to the mainfrm.cpp file, find begin_message_map, add an on_cbn_selendok (id_tool_zoom, oneselectzoomed). Then, of course, it is to implement its processing function, the process function is as follows:

Void CMAINFRAME :: Onselectrzoomed ()

{

// Get the content and the msgbox is displayed

CSTRING STRCONTENT;

m_wndtoolbar.m_wndzoom.getWindowText (StrContent);

AfxMessageBox (strContent); // Pop up the selected content

}

Xiao Gong, then it is compiled, run. Look at the interface, it is indeed a flat, and the toolbar of the control control.

Author Note: I haven't written a text for a long time. This is the first essay written after I am in the society. If you write it, please bear with you! J

My email is lijf971@21cn.com, what is good, I hope to send it to me J

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

New Post(0)