CToolBar Extended Class Ctoolbarex

Source: Internet
Author: User
Tags class definition split

We know that the tool bar in the program is generated in the CMainFrame, the class is CToolBar, it is very complicated to use. For this reason, the common functions of CToolBar are encapsulated, which generates an inheritance class Ctoolbarex, which simplifies the operation greatly. Compilation environment: Windows Server SP3 (en), vc++6.0 SP5. See how to use First:

See how to use First:

Define variables in CMainFrame first

Ctoolbarex Tbex;

Add the following code to the CMainFrame OnCreate () function:

First create toolbar, replace the original code

Tbex. CreateEx (This, Tbstyle_flat, Ws_child | ws_visible | Cbrs_top | Cbrs_tooltips | cbrs_flyby | Cbrs_size_dynamic);

Set the number of buttons, the split bar is also counted a OH

Tbex. Setbuttonnumber (5);

Add a picture

Tbex. AddIcon (AfxGetApp ()->loadicon (idr_mainframe));

Tbex. AddIcon (AfxGetApp ()->loadicon (Idr_tbtype));

Tbex. AddIcon (AfxGetApp ()->loadicon (Idi_swire));

Tbex. AddIcon (AfxGetApp ()->loadicon (Idi_icon1));

Set the position, ID, picture index, and text for each button

Tbex. Setbutton (0,id_app_about,0, "employee");

Tbex. Setbutton (1,id_app_exit,1, "feed");

Add a split bar

Tbex. AddSeparator (2);

Tbex. Setbutton (3,id_app_about,2, "Swire");

Tbex. Setbutton (4,id_app_about,3, "Coca");

Set each button size

Tbex.  SetSize (); or Tbex. Setdefaultsize ()

In this way, a beautiful toolbar is now in front of us, is not very simple AH.

Class definition

class CToolBarEx : public CToolBar
{
public:    CToolBarEx();
public:
//设置图片大小 
void SetImageSize(int nImageWidth,int nImageHeight);
//加入图片
void AddBitmap(CBitmap* pbmImage, COLORREF crMask);
void AddBitmap(CBitmap* pbmImage, CBitmap* pbmMask);
void AddIcon(HICON hIcon);
//设置按钮大小为默认大小
void SetDefaultSize();
//加入分割条
void AddSeparator(int nButton);
//设置按钮大小,默认是50X40,具体设定必须符合ToolBar的要求,可以自己调
void SetSize(int nWidth=50,int nHeight=40);
//设置按钮图片和文字
void SetButton(int nButton,int nID, int nImage,LPTSTR lpText);
//设置按钮图片无文字
void SetButton(int nButton,int nID, int nImage);
//设置按钮个数
void SetButtonNumber(int n);
//加入图片到ToolBarEx,在AddIcon()和AddBitmap()中自动调用
void SetImage();
//图片变量
CImageList img;
//图片大小变量
CSize sizeImage;
virtual ~CToolBarEx();
protected:
DECLARE_MESSAGE_MAP()
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.