Esempio n. 1
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));
	}
}
Esempio n. 2
0
	/**-----------------------------------------------------------------------------
		Initializes menu or toolbar item's caption, icon, and command id.
	------------------------------------------------------------------------------*/
	void InitializeItem(Office::CommandBarControlPtr item, UINT command_id)
	{
		CString caption;
		caption.LoadString(command_id);
	    item->put_Caption(bstr_t(caption));

	    // The target action is marker add-on, since we work using MarkerEvent.
	    // For more information about that, see the article in MSDN: 
	    // http://msdn.microsoft.com/en-us/library/aa140366.aspx

		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));

		m_buttons.Add(new ClickEventRedirector(item));
	}