CButtonST Usage Tips: cbuttonst introduction

Source: Internet
Author: User

CButtonST gives me the most powerful, most functional CButton derived class I have ever seen. The purpose of this article is not to discuss the technology, but to provide you with a reference to the use of cbuttonst to improve the speed of programming.

It's a couple of buttons made with CButtonST.

Here are some version information of the CButtonST class, so that you can get the latest version of it in time.

Davide Calabro

Email address: [Email protected]

Personal homepage: http://www.softechsoftware.it

The CButtonST class mainly includes four files of BtnST.h, BtnST.cpp, BCMenu.h and BCMenu.cpp. If you plan to use CButtonST's window more than one, then I suggest you in VC + + workspace | After importing the above four files in FileView, then add the appropriate include statement in the SdtAfx.h file, such as # include "BtnST.h".

In the next few articles, I'll show you the various common methods of CButtonST based on the demo program provided by the author. In the last article, we will provide you with the CButtonST class of Chinese documents for your reference in future use.

This article mainly includes the following effects:

1. Add icon to the button to display the icon and text simultaneously

2. Display the flat button

3. Make the icon on the button variable

4. Set the background and text color of the button in different states

5. Setting the location of icons and text

6. Set the shape of the button according to the icon's shape

7. Add ToolTips

The following is a demo interface for basic features:

Effect One: Add icon to the button to display the icon and text simultaneously

Suppose the button ID is idc_button1

1. Adding member variables

1. CButtonST   m_btn;

2. Add the icon resource, set its ID to Idi_icon1

3. Initialize the button in the OnInitDialog function

1. m_btn.SubclassDlgItem(IDC_BUTTON1, this ); 2. m_btn.SetIcon(IDI_ICON1); 3. m_btn.SetFlat(FALSE);

Note: To achieve the best results, adjust the size of the button according to the size of the icon.

Example: The Standar button in the demo program.

Effect two: Show Flat button

Only need to put m_btn on the basis of effect one. Setflat (FALSE); The statement is removed.

Effect three: Make the icon on the button variable

Suppose the button ID is idc_button1

1. Adding member variables

1. CButtonST   m_btn;

2. Add two icon resources with ID set to Idi_icon1 and Idi_icon2

Idi_icon1 is an icon of the normal state, Idi_icon2 is the icon when pressed

3. Initialize the button in the OnInitDialog function

1. m_btn.SubclassDlgItem(IDC_BUTTON1, this ); 2. m_btn.SetIcon(IDI_ICON2,IDI_ICON1);

Example: The Halloween button in the demo program.

effect Four: Set the background and text color of the button in different states

Suppose the button ID is idc_button1

1. Adding member variables

1. CButtonST   m_btn;

2. Add the icon resource, set its ID to Idi_icon1

3. Initialize the button in the OnInitDialog function

1. m_btn.SubclassDlgItem(IDC_BUTTON1, this ); 2. m_btn.SetIcon(IDI_ICON1); 3. m_btn.SetColor(CButtonST::BTNST_COLOR_BK_OUT, RGB(208,208,208)); 4. m_btn.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, RGB(208,208,208)); 5. m_btn.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);

Tip: The first parameter of the SetColor function and the Offsetcolor function represents the state of the button, and the foreground color is the colour of the text, and their value is expressed as:

1. BTNST_COLOR_BK_IN   //鼠标放在按钮内时的背景色 2. BTNST_COLOR_FG_IN,  //鼠标放在按钮内时的前景色 3. BTNST_COLOR_BK_OUT, //普通状态时的背景色  4. BTNST_COLOR_FG_OUT, //普通状态时的前景色 5. BTNST_COLOR_BK_FOCUS,   //按钮被按下后的背景色 6. BTNST_COLOR_FG_FOCUS,   //按钮被按下后的前景色

Example: 48x48 icon button, zip button, etc. in the demo program.

Effect Five: Set the position of the icon and text

Suppose the button ID is idc_button1

1. Adding member variables

1. CButtonST   m_btn;

2. Add icon resource with ID set to Idi_icon1

3. Initialize the button in the OnInitDialog function

1. m_btn.SubclassDlgItem(IDC_BUTTON1, this ); 2.      m_btn.SetIcon(IDI_ICON1); 3.      m_btn.SetAlign(CButtonST::ST_ALIGN_VERT);

Tip: The first parameter of the Setalign function represents the location information, by default, the text is to the right of the icon

1. ST_ALIGN_HORIZ  // 文字在右 2. ST_ALIGN_VERT   //文字在下 3. ST_ALIGN_HORIZ_RIGHT // 文字在左

Instance: The Search button in the demo program.

Effect Six: Sets the shape of the button according to the shape of the icon

Suppose the button ID is idc_button1

1. Adding member variables

1. CButtonST   m_btn;

2. Add the icon resource, set its ID to Idi_icon1

3. Initialize the button in the OnInitDialog function

1. m_btn.SubclassDlgItem(IDC_BUTTON1, this ); 2. m_btn.SetIcon(IDI_ICON1); 3. m_btn.DrawBorder(FALSE); 4. m_btn.SetColor(CButtonST::BTNST_COLOR_BK_OUT, RGB(208,208,208)); 5. m_btn.SetColor(CButtonST::BTNST_COLOR_BK_IN, RGB(208,208,208)); 6. m_btn.SetColor(CButtonST::BTNST_COLOR_BK_FOCUS, RGB(208,208,208));

Note: To achieve the best results, adjust the size of the button according to the size of the icon.

and set the background color according to the actual situation. Please remove the text of the button in advance.

Effect Seven: Add tooltips

Suppose the button ID is idc_button1

1. Adding member variables

1. CButtonST   m_btn;

2. Add the icon resource, set its ID to Idi_icon1

3. Initialize the button in the OnInitDialog function

1. m_btn.SubclassDlgItem(IDC_BUTTON1, this ); 2. m_btn.SetIcon(IDI_ICON1); 3. m_btn.SetTooltipText(_T( "This is a tooltip.\r\nMultiline!" ));

The previous article "CButtonST Use Technique (i)" introduces the 7 kinds of techniques used by cbuttonst, this article mainly includes the following effects:

1. Change the shape of the mouse when it enters the button (hyperlink effect)

2. Menu button

3. Bitmap button

4. Button Focus

5. CheckBox button

6. Transparent button (Button background and window background)

7. Special PictureBox

Effect one: Change the shape when the mouse enters the button (hyperlink effect)

Suppose the button ID is idc_button1

1. Adding member variables

1. CButtonST    m_btn;

2. Add the icon resource, set its ID to Idi_icon1

3. Initialize the button in the OnInitDialog function

1. m_btn.SubclassDlgItem(IDC_BUTTON1, this ); 2. m_btn.SetIcon(IDI_ICON1); 3. m_btn.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30); 4. m_btn.SetURL( "www.scut.edu.cn" ); 5. m_btn.SetTooltipText( "www.scut.edu.cn" ); 6. m_btn.SetBtnCursor(IDC_CURSOR1);

Effect Two: Menu button

Suppose the button ID is idc_button1

1. Adding member variables

1. CButtonST    m_btn;

2. Add the icon resource, set its ID to Idi_icon1

3. Add Menu,id set to Idr_menu

4. Initialize the button in the OnInitDialog function

1. m_btn.SubclassDlgItem(IDC_BUTTON1, this ); 2. m_btn.SetIcon(IDI_ICON1); 3. m_btn.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30); 4. m_btn.SetMenu(IDR_MENU, m_hWnd);

Note: The menu effect is similar to the right-click menu, and it is sufficient to set only one column when setting menu options. In addition, the width of the menu is related to the text length of the menu, the space placeholder can be used to achieve the best results.

Ways to introduce bitmaps in menus

1. Add toolbar, and then use the menu item ID as the ID of the toolbar button.

The button icon on the 2.ToolBar is displayed in the corresponding menu item.

Put the m_btn in the above code. SetMenu (Idr_menu, m_hwnd);

Change to M_BTN. SetMenu (Idr_menu, M_hwnd, TRUE, Idr_toolbar);

Idr_toolbar is the ID of the corresponding toolbar.

Effect Three: Bitmap button

Suppose the button ID is idc_button1

1. Adding member variables

1. CButtonST    m_btn;

2. Add bitmap resource with ID set to IDB_BITMAP1

3. Initialize the button in the OnInitDialog function

1. m_btn.SubclassDlgItem(IDC_BUTTON1, this );     2. m_btn.SetBitmaps(IDB_BITMAP1,RGB(0,0,0)); 3. m_btn.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);

tip: The Setbitmaps function above sets the point in the picture with the color value RGB (0,0,0) to be transparent.

Effect Four: Button focus

Suppose the button ID is idc_button1

1. Adding member variables

1. CButtonST    m_btn;

2. Add the icon resource, set its ID to Idi_icon1

3. Initialize the button in the OnInitDialog function

1. m_btn.SubclassDlgItem(IDC_BUTTON1, this ); 2. m_btn.SetIcon(IDI_ICON1); 3. m_btn.SetAlign(CButtonST::ST_ALIGN_VERT); 4. m_btn.DrawFlatFocus(TRUE);

Effect Five: CheckBox button

Suppose the button ID is idc_button1

1. Adding member variables

1. CButtonST    m_btn;

2. Add icon resource with ID set to Idi_icon1 and Idi_icon2

3. Initialize the button in the OnInitDialog function

1. m_btn.SubclassDlgItem(IDC_CHECK1, this ); 2. m_btn.SetIcon(IDI_ICON1,IDI_ICON2); 3. m_btn.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);

Tips:

Idi_icon1 the icon that is displayed when selected

Idi_icon2 as the icon for the selected time

Effect VI: Transparent button

Suppose the button ID is idc_button1

1. Adding member variables

1. CButtonST    m_btn;

2. Add icon resource with ID set to Idi_icon1

3. Initialize the button in the OnInitDialog function

1. m_btn.SubclassDlgItem(IDC_BUTTON1, this ); 2. m_btn.SetIcon(IDI_ICON1); 3. m_btn.DrawTransparent(TRUE);

Effect VII: Special PictureBox

Using CButtonST's special display style, it can be used as a PictureBox control. The button's properties are usually set to disable.
Example: CButtonST is used instead of PictureBox in the About page of the demo program.

This article will introduce you to the two CButtonST derived classes.

First, Cwinxpbuttonst class

The Cwinxpbuttonst class is a derived class of cbuttonst. It is characterized by the use of a rounded, black border style in the windowsxp. It includes WinXPButtonST.h and WinXPButtonST.cpp two files, and since it is derived from cbuttonst, it is also necessary to introduce cbuttonst files when referencing it.

Use:

1. Introduction of files, adding files

2. After importing the file, add it in the SdtAfx.h file

1. #include "WinXPButtonST.h"

3. Adding member variables

1. CWinXPButtonST    m_btn2;

4. Assume that the button ID is Idc_button

Add icon resource with ID set to Idi_icon1

5. Initialize the button in the OnInitDialog function

1. m_btn2.SubclassDlgItem(IDC_BUTTON, this ); 2. m_btn2.SetIcon(IDI_ICON1); 3. m_btn2.SetRounded(TRUE);

Note: However, there is a lack of it, that is, the rounded corners of the buttons are drawn, and the shape of the buttons is still the original rectangle. So if you use the button in a window with a background color, it will be quite an eyesore.

, showing unsightly sharp corners in the black background color:

The solution is to use the SetColor function to make the background of the button consistent with the background of the window.

Second, Cshadebuttonst class

The Cshadebuttonst class is another derived class of CButtonST. It is characterized by support for a more diverse background, through the Setshade function can set 9 kinds of background effect for the button. It includes four files, which are CeXDib.h, CeXDib.cpp, ShadeButtonST.h, and ShadeButtonST.cpp, respectively. When referencing it, it is also necessary to introduce cbuttonst files as well.

Use:

1. Introduction of files, adding files

2. After importing the file, add it in the SdtAfx.h file

1. #include "ShadeButtonST.h"

3. Adding member variables

1. CShadeButtonST  m_btn3;

4. Assume that the button ID is Idc_button3

Add icon resource with ID set to Idi_icon1

5. Initialize the button in the OnInitDialog function

1. m_btn3.SubclassDlgItem(IDC_BUTTON3, this ); 2. m_btn3.SetIcon(IDI_ICON1); 3. m_btn3.SetShade(CShadeButtonST::SHS_METAL);

A variety of background effects and corresponding parameter values are given below.

From:http://www.vckbase.com/index.php/wenku/index

Http://www.vckbase.com/index.php/wv/342.html

Http://www.vckbase.com/index.php/wenku/index

CButtonST Usage Tips: cbuttonst introduction

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.