private NativeMethods.TBBUTTONINFO GetButtonInfo(int index)
{
CommandBarItem item = items[index];
NativeMethods.TBBUTTONINFO buttonInfo = new NativeMethods.TBBUTTONINFO();
buttonInfo.cbSize = Marshal.SizeOf(typeof(NativeMethods.TBBUTTONINFO));
buttonInfo.dwMask = NativeMethods.TBIF_IMAGE | NativeMethods.TBIF_STATE | NativeMethods.TBIF_STYLE | NativeMethods.TBIF_COMMAND;
buttonInfo.idCommand = index;
buttonInfo.iImage = NativeMethods.I_IMAGECALLBACK;
buttonInfo.fsStyle = NativeMethods.BTNS_BUTTON | NativeMethods.BTNS_AUTOSIZE;
buttonInfo.fsState = 0;
buttonInfo.cx = 0;
buttonInfo.lParam = IntPtr.Zero;
buttonInfo.pszText = IntPtr.Zero;
buttonInfo.cchText = 0;
if (!item.IsVisible)
{
buttonInfo.fsState |= NativeMethods.TBSTATE_HIDDEN;
}
CommandBarComboBox comboBox = item as CommandBarComboBox;
if (comboBox != null)
{
buttonInfo.cx = (short) (comboBox.Width + 4);
buttonInfo.dwMask = NativeMethods.TBIF_SIZE;
}
if (item is CommandBarSeparator)
{
buttonInfo.fsStyle |= NativeMethods.BTNS_SEP;
}
else
{
if (item.IsEnabled)
{
buttonInfo.fsState |= NativeMethods.TBSTATE_ENABLED;
}
CommandBarMenu menu = item as CommandBarMenu;
if ((menu != null) && (menu.Items.Count > 0))
{
buttonInfo.fsStyle |= NativeMethods.BTNS_DROPDOWN;
}
if ((style == CommandBarStyle.ToolBar) || (this.Style == CommandBarStyle.TextToolBar))
{
if (item is CommandBarMenu)
{
buttonInfo.fsStyle |= NativeMethods.BTNS_WHOLEDROPDOWN;
}
}
CommandBarCheckBox checkBox = item as CommandBarCheckBox;
if ((checkBox != null) && (checkBox.IsChecked))
{
buttonInfo.fsState |= NativeMethods.TBSTATE_CHECKED;
}
}
if (item is CommandBarSeparator)
{
buttonInfo.iImage = NativeMethods.I_IMAGENONE;
}
else if (item.Image != null)
{
buttonInfo.iImage = index;
}
if (((this.Style == CommandBarStyle.Menu)||(this.Style == CommandBarStyle.TextToolBar)) && (item.Text != null) && (item.Text.Length != 0))
{
buttonInfo.dwMask |= NativeMethods.TBIF_TEXT;
buttonInfo.pszText = Marshal.StringToHGlobalUni(item.Text + "\0");
buttonInfo.cchText = item.Text.Length;
}
return buttonInfo;
}