Ejemplo n.º 1
0
	void FillMenuItems(long position, Office::CommandBarControlsPtr menu_items, HMENU popup_menu)
	{
		// For each items in the menu,
		bool begin_group = false;
		for (int i = 0; i < GetMenuItemCount(popup_menu); ++i)
		{
			HMENU sub_menu = GetSubMenu(popup_menu, i);

			// set item caption
			WCHAR item_caption[1024] = L"";
			GetMenuString(popup_menu, i, item_caption, 1024, MF_BYPOSITION);

			// if this item is actually a separator then process next item
			if (lstrlen(item_caption) == 0)
			{
				begin_group = true;
				continue;
			}

			// create new menu item.
			Office::CommandBarControlPtr menu_item_obj;
			menu_items->Add(
				variant_t(sub_menu ? long(Office::msoControlPopup) : long(Office::msoControlButton)), 
				vtMissing, 
				vtMissing, 
				position < 0 ? vtMissing : variant_t(position), 
				variant_t(true),
				&menu_item_obj);

			if (position > 0)
				++position;

			// obtain command id from menu
			UINT command_id = GetMenuItemID(popup_menu, i);

			// normal command; set up visio menu item
			InitializeItem(menu_item_obj, command_id);

			// if current item is first in a group, start new group
			if (begin_group)
			{
				menu_item_obj->put_BeginGroup(VARIANT_TRUE);
				begin_group = false;
			}

			// if this command has sub-menu
			if (sub_menu)
			{
				Office::CommandBarPopupPtr popup_menu_item_obj = menu_item_obj;

				Office::CommandBarControlsPtr controls;
				popup_menu_item_obj->get_Controls(&controls);

				FillMenuItems(-1, controls, sub_menu);
			}
		}
	}
Ejemplo n.º 2
0
void AddinUi::InstallButtons(Office::CommandBarControlsPtr menu_items, CMenu* popup_menu )
{
	// For each items in the menu,

	for (UINT i = 0; i < popup_menu->GetMenuItemCount(); ++i)
	{
		CMenu* sub_menu = popup_menu->GetSubMenu(i);

		// set item caption
		CString item_caption;
		popup_menu->GetMenuString(i, item_caption, MF_BYPOSITION);

		// create new menu item.
		Office::CommandBarControlPtr item;
		menu_items->Add(
			variant_t(long(Office::msoControlButton)), 
			vtMissing, 
			vtMissing, 
			vtMissing, 
			variant_t(true),
			&item);

		// obtain command id from menu
		UINT command_id = popup_menu->GetMenuItemID(i);

		CString caption;
		caption.LoadString(command_id);
		item->put_Caption(bstr_t(caption));

		CString parameter;
		parameter.Format(L"%d", command_id);
		item->put_Parameter(bstr_t(parameter));

		// Set unique tag, so that the command is not lost
		CString tag;
		tag.Format(L"%s_%d", ADDON_NAME, command_id);
		item->put_Tag(bstr_t(tag));

		UpdateButton(item, command_id);

		m_buttons.Add(new ClickEventRedirector(item, tag, command_id));
	}
}