After importing the file, add it to the SdtAfx.h fileĪdd Icon resource, ID is set to IDI_ICON1ĥ. It includes WinXPButtonST.h and WinXPButtonST.cpp two files, and because it is derived from CButtonST, so when quoting it, the CButtonST file should be imported together.Ģ. It is characterized by using the rounded corners and black border style in WindowsXP. The CWinXPButtonST class is a derived class of CButtonST. At this time, the button's attribute is generally set to disable.Įxample: CButtonST is used instead of PictureBox in the About page of the demo program. With the special display style of CButtonST, it can be used as a PictureBox control. IDI_ICON1 is the icon displayed when selected Add Icon resource, ID is set to IDI_ICON1 and IDI_ICON2 Tip: The above SetBitmaps function will set the points with the color value of RGB(0,0,0) in the picture as transparent.Ģ. Add bitmap resource, ID is set to IDB_BITMAP1 IDR_TOOLBAR is the ID of the corresponding ToolBar.Ģ.
#MFC SET ICON ON BUTTON CODE#
The button icon on ToolBar will be displayed in the corresponding menu item.Ĭhange m_btn.SetMenu(IDR_MENU, m_hWnd) in the above code Ĭhange to m_btn.SetMenu(IDR_MENU, m_hWnd, TRUE, IDR_TOOLBAR)
Add ToolBar, and use Menu menu item ID as ToolBar button ID in turn.Ģ. In addition, the width of the menu is related to the text length of the menu, you can use spaces to occupy the space to achieve the best effect.ġ. Note: The effect of the menu is similar to that of the right-click menu, so only one column is enough when setting menu options. Initialize the button in the OnInitDialog function M_btn.SetURL("m_btn.SetTooltipText("m_btn.SetBtnCursor(IDC_CURSOR1) Ĥ. M_btn.SetTooltipText(_T("This is a tooltip.\r\nMultiline!")) Įffect 1: Change the shape when the mouse enters the button (hyperlink effect) Please remove the text of the button in advance. M_btn.SetColor(CButtonST::BTNST_COLOR_BK_IN, RGB(208,208,208)) Īnd set the background color according to the actual situation. By default, the text is on the right side of the iconĮxample: Search button in the demo program.Įffect 6: Set the shape of the button according to the shape of Icon Tip: The first parameter of the SetAlign function represents the position information. M_btn.SetAlign(CButtonST::ST_ALIGN_VERT) Add Icon resource, ID is set to IDI_ICON1 in the demo program.Įffect 5: Set the position of the icon and textĢ.
#MFC SET ICON ON BUTTON ZIP#
The foreground color is the color of the text, and their values indicate:īTNST_COLOR_BK_IN //The background color when the mouse is placed in the buttonīTNST_COLOR_FG_IN, //Foreground color when the mouse is placed in the buttonīTNST_COLOR_BK_OUT, //Background color in normal stateīTNST_COLOR_FG_OUT, //Foreground color in normal stateīTNST_COLOR_BK_FOCUS, //Background color after the button is pressedīTNST_COLOR_FG_FOCUS, //Foreground color after the button is pressedĮxample: 48×48 icon button, Zip button, etc. Tip: The first parameter of the SetColor function and the OffsetColor function represents the state of the button. M_btn.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30) IDI_ICON1 is the icon in the normal state, IDI_ICON2 is the icon when pressedĮxample: Halloween button in the demo program.Įffect 4: Set the background color and text color of the button in different states Add two Icon resources, ID is set to IDI_ICON1 and IDI_ICON2 Only need to remove m_btn.SetFlat(FALSE) statement on the basis of effect 1.Įffect 3: Make the icon on the button changeableĢ. Note: For best results, please adjust the size of the button according to the size of the Icon.Įxample: the Standar button in the demo program. Add Icon resource and set its ID to IDI_ICON1ģ. The following is a demo interface made by CButtonST class (with source code):Įffect 1: Add Icon to the button to display both Icon and textĢ.
In the next article, I will introduce to you various common methods of CButtonST based on the demo program.
First copy the above 4 files to your own project, then open the project in the VC++ development environment, select, a dialog box for inserting files into the project will pop up, and then select the project directory For the above 4 files, click the button to add 4 files to the current project, and add appropriate include statements to the SdtAfx.h file, such as #include "BtnST.h". The CButtonST class mainly includes four files: BtnST.h, BtnST.cpp, BCMenu.h and BCMenu.cpp. Here we introduce the powerful button class CButtonST, which can make your program icing on the cake.