MFC内置TBBUTTON结构

Contains information about a button in a toolbar.工具栏中一个按钮的信息

Syntax

C++
复制代码
typedef struct {
  int       iBitmap;
  int       idCommand;
  BYTE      fsState;
  BYTE      fsStyle;
#ifdef _WIN64
  BYTE      bReserved[6];
#else 
#if defined(_WIN32)
  BYTE      bReserved[2];
#endif 
#endif 
  DWORD_PTR dwData;
  INT_PTR   iString;
} TBBUTTON, *PTBBUTTON, *LPTBBUTTON;

Members

iBitmap

Type: int

Zero-based index of the button image. Set this member to I_IMAGECALLBACK, and the toolbar will send theTBN_GETDISPINFO notification code to retrieve the image index when it is needed.

Version 5.81. Set this member to I_IMAGENONE to indicate that the button does not have an image. The button layout will not include any space for a bitmap, only text.

If the button is a separator, that is, if fsStyle is set to BTNS_SEP, iBitmap determines the width of the separator, in pixels. For information on selecting button images from image lists, seeTB_SETIMAGELIST message.

idCommand

Type: int

Command identifier associated with the button. This identifier is used in a WM_COMMAND message when the button is chosen.

fsState

Type: BYTE

Button state flags. This member can be a combination of the values listed in Toolbar Button States.

fsStyle

Type: BYTE

Button style. This member can be a combination of the button style values listed inToolbar Control and Button Styles.

bReserved[6]

Type: BYTE

Reserved.

bReserved[2]

Type: BYTE

Reserved.

dwData

Type: DWORD_PTR

Application-defined value.

iString

Type: INT_PTR

Zero-based index of the button string, or a pointer to a string buffer that contains text for the button.

Remarks

The iString member can return either a string pointer or an index. You can use theIS_INTRESOURCE macro to determine which is returned.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Commctrl.h

 

 

 

This structure contains information about a button in a toolbar.

typedef struct _TBBUTTON { int iBitmap; int idCommand; BYTE fsState; BYTE fsStyle; DWORD dwData; int iString; } TBBUTTON, NEAR* PTBBUTTON, FAR* LPTBBUTTON;typedef const TBBUTTON FAR* LPCTBBUTTON;Members
iBitmap
Zero-based index of the button image.
idCommand
Command identifier associated with the button. This identifier is used in a WM_COMMAND message when the button is chosen.
fsState
Button state flags. It can be a combination of the values listed in   Creating a Toolbar.
fsStyle
Button style. It can be a combination of the button style values listed in   Control Styles.
dwData
Specifies an application-defined value.
iString
Zero-based index of the button string.
Requirements

OS Versions: Windows CE 1.0 and later.
Header: Commctrl.h.

TBBUTTON tbButton[ICONSUM] = {0};
m_ImageList.Create(32, 32, ILC_COLOR32 | ILC_MASK, 0, 0);
m_ImageList.Add(::AfxGetApp()->LoadIcon(IDI_ICON3));
m_ImageList.Add(::AfxGetApp()->LoadIcon(IDI_ICON1));
m_ImageList.Add(::AfxGetApp()->LoadIcon(IDI_ICON4));
m_ImageList.Add(::AfxGetApp()->LoadIcon(IDI_ICON5));
m_ImageList.Add(::AfxGetApp()->LoadIcon(IDI_ICON2));
m_ToolBar.Create(WS_CHILD | WS_VISIBLE, CRect(0, 0, 0, 0), this, 0);
m_ToolBar.SetImageList(&m_ImageList);
for(int i=0; i< ICONSUM; i++)
{
   tbButton[i].dwData   = NULL;
   tbButton[i].fsState   = TBSTATE_ENABLED;
   tbButton[i].fsStyle   = (BYTE)TBSTYLE_FLAT;
   tbButton[i].iBitmap   = i;
  
}
tbButton[0].idCommand = ID_ATTENDANCE_RECORD;
tbButton[1].idCommand = IDM_REQUEST_EMPLOYEE;
tbButton[2].idCommand = IDM_PAYLIP;
tbButton[3].idCommand = IDM_PORTFOLIO;
tbButton[4].idCommand = ID_ABOUT;

m_ToolBar.AddButtons(ICONSUM, tbButton);
m_ToolBar.AutoSize();
m_ToolBar.SetStyle(TBSTYLE_FLAT | CCS_TOP);

m_Menu.LoadMenu(IDR_MAINFRAME_MENU);
SetMenu(&m_Menu);

 

 

 

TBBUTTONINFO的使用。

 

MSDN 对TBBUTTONINFO 的解释为

This structure contains or receives information for a specific button in a toolbar.

 

  1. typedef struct {  UINT cbSize;   
  2.                   DWORD dwMask;    
  3.                   int idCommand;   
  4.                   int iImage;  
  5.                   BYTE fsState;   
  6.                   BYTE fsStyle;   
  7.                   WORD cx;  
  8.                   DWORD lParam;    
  9.                   LPTSTR pszText;  
  10.                   int cchText;  
  11. } TBBUTTONINFOA, *LPTBBUTTONINFOA;  

在你创建一个Toolbar 后,如何修改Toolbar 的样式呢

下面的代码允许你在Toolbar的一个按钮中添加一个向下的箭头。

[c-sharp] view plain copy print ?
  1. TBBUTTONINFO tbbi = { sizeof(TBBUTTONINFO), TBIF_STYLE };  
  2.   
  3.  tb.SetButtonStructSize();  
  4.  tb.GetButtonInfo ( IDC_CHOOSE_BKGND_BMP, &tbbi );  
  5.  tbbi.fsStyle |= BTNS_WHOLEDROPDOWN;  
  6.  tb.SetButtonInfo ( IDC_CHOOSE_BKGND_BMP, &tbbi );  
  7.   
  8.   ....  
  9.   
  10.  UIAddToolBar(m_hWndToolBar); 

 

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值