Example #1
0
		public static extern void SendMessage(IntPtr hWnd, int msg, int wParam, ref TBBUTTONINFO lParam);
Example #2
0
		TBBUTTONINFO GetButtonInfo(int index)
		{
			ToolBarItem item = items[index];
			TBBUTTONINFO tbi = new TBBUTTONINFO();
			tbi.cbSize = Marshal.SizeOf(typeof(TBBUTTONINFO));
			tbi.dwMask = (int)(ToolBarButtonInfoFlags.TBIF_IMAGE | ToolBarButtonInfoFlags.TBIF_STATE |
				 ToolBarButtonInfoFlags.TBIF_STYLE | ToolBarButtonInfoFlags.TBIF_COMMAND | ToolBarButtonInfoFlags.TBIF_SIZE);
			tbi.idCommand = index;
			tbi.iImage = (int)ToolBarButtonInfoFlags.I_IMAGECALLBACK;
			tbi.fsState = 0;
			tbi.cx = 0;
			tbi.lParam = IntPtr.Zero;
			tbi.pszText = IntPtr.Zero;
			tbi.cchText = 0;

			if ( item.Style == ToolBarItemStyle.ComboBox )
			{
				tbi.fsStyle = (int)(ToolBarButtonStyles.TBSTYLE_BUTTON) ;
				tbi.cx = (short)item.ComboBox.Width;
				WindowsAPI.SetParent(item.ComboBox.Handle, Handle);
			}
			else if ( item.Text != null && item.Text != string.Empty )
			{
				tbi.fsStyle = (int)(ToolBarButtonStyles.TBSTYLE_BUTTON);
				tbi.cx = MARGIN;
				if ( item.Image != null )
					tbi.cx += (short)(item.Image.Size.Width + MARGIN);
				if ( item.Style == ToolBarItemStyle.DropDownButton )
					tbi.cx += DROWPDOWN_ARROW_WIDTH;
				Graphics g = CreateGraphics();
				string currentText = item.Text;
				int amperSandIndex = currentText.IndexOf('&');
				if ( amperSandIndex != -1 )
					currentText = item.Text.Remove(amperSandIndex, 1);
				Size size = TextUtil.GetTextSize(g, currentText, SystemInformation.MenuFont);
				g.Dispose();
				if ( barType == BarType.MenuBar)
				{
					tbi.cx += (short)(size.Width + 2*MENUTEXT_MARGIN);
				}
				else
					tbi.cx += (short)(size.Width + 2*MARGIN);

				tbi.dwMask |= (int)ToolBarButtonInfoFlags.TBIF_TEXT;
				tbi.pszText = Marshal.StringToHGlobalAuto(item.Text + "\0");
				tbi.cchText = item.Text.Length;

				if (  IsCommonCtrl6() && barType != BarType.MenuBar )
				{
					// If we let the operating system do the drawing
					// the DROWPDOWN_ARROW_WIDTH is slightly bigger than
					// the value we are using add some padding to compensate
					tbi.cx += 6;
				}

			}
			else
			{
				tbi.fsStyle = (int)(ToolBarButtonStyles.TBSTYLE_BUTTON | ToolBarButtonStyles.TBSTYLE_AUTOSIZE );
				tbi.cx = 0;
			}

			if (!item.Visible)
				tbi.fsState |= (int)ToolBarButtonStates.TBSTATE_HIDDEN;

			if (item.Style == ToolBarItemStyle.Separator)
			{
				tbi.fsStyle |= (int)ToolBarButtonStyles.TBSTYLE_SEP;
			}
			else
			{
				if (item.Enabled)
					tbi.fsState |= (int)ToolBarButtonStates.TBSTATE_ENABLED;

				if ( item.Style == ToolBarItemStyle.DropDownButton )
					tbi.fsStyle |= (int)ToolBarButtonStyles.TBSTYLE_DROPDOWN;

				if (item.Style == ToolBarItemStyle.PushButton)
					if (item.Checked)
						tbi.fsState |= (int)ToolBarButtonStates.TBSTATE_CHECKED;
			}

			if (item.Style == ToolBarItemStyle.Separator )
				tbi.iImage = (int)ToolBarButtonInfoFlags.I_IMAGENONE;
			else if (item.Image != null)
				tbi.iImage = index;

			return tbi;
		}
Example #3
0
 public static extern void SendMessage(IntPtr hWnd, int msg, int wParam, ref TBBUTTONINFO lParam);