cancel
Showing results for 
Search instead for 
Did you mean: 

Menu

Former Member
0 Kudos

HI

How to Add the Menu.Not a menu item.if u have a code then send me.

Accepted Solutions (1)

Accepted Solutions (1)

Nussi
Active Contributor
0 Kudos

Hi,

altough there should be already hundreds of samples in this forum i post

a c# code snippet how to add a menu with menuitems:


        SAPbouiCOM.Menus oMenus = null;
        SAPbouiCOM.MenuItem oMenuItem = null;

        // Get the menus collection from the application
        oMenus = globals.SBO_Application.Menus;

        SAPbouiCOM.MenuCreationParams oCreationPackage = null;
        oCreationPackage = ((SAPbouiCOM.MenuCreationParams)(globals.SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_MenuCreationParams)));
        oMenuItem = globals.SBO_Application.Menus.Item("43520"); // modules'

        string sPath = null;
        sPath = System.IO.Directory.GetParent(Application.ExecutablePath).ToString();

        // find the place in wich you want to add your menu item
        // in this example I chose to add my menu item under
        // SAP Business One.
        oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_POPUP;
        oCreationPackage.UniqueID = "Project01";
        oCreationPackage.String = "YourMenuName";
        oCreationPackage.Enabled = true;
        //oCreationPackage.Image = sPath + "\\b1_14x18.bmp";
        oCreationPackage.Position = 15;

        oMenus = oMenuItem.SubMenus;        

         //  If the manu already exists this code will fail
         oMenus.AddEx(oCreationPackage);

         // Get the menu collection of the newly added pop-up item
         oMenuItem = globals.SBO_Application.Menus.Item("Project01");
         oMenus = oMenuItem.SubMenus;

         // Create s sub menu
         oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING;
         oCreationPackage.UniqueID = "Entry1";
         oCreationPackage.String = "YourMenuItemName"
         oMenus.AddEx(oCreationPackage);

lg David

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Don't know if I get what you are trying to accomplish, but I guess you need one of the following:

1. Create a different Main Menu: You can create a new form that act as a new menu OR you can hide all the entries in the main menu and add your's.

2. Create a new Module for your add-on. You can achieve this with the following code.

Functions to Add menus:


    Public Function AddMenus(ByRef oCompany As SAPbobsCOM.Company, ByRef oApplication As SAPbouiCOM.Application) As Boolean
        Dim oForm As SAPbouiCOM.Form = Nothing
        Dim oXMLDoc As System.Xml.XmlDocument = New Xml.XmlDocument
        AddMenus = False

        Try
            oForm = oApplication.Forms.GetFormByTypeAndCount(169, 1) '// Apanhar a referência do formulário do menu principal
            oForm.Freeze(True) 

            oXMLDoc.load(sPath & "menuAdd.xml")
            oApplication.LoadBatchActions(oXMLDoc.InnerXml)

            ' // Set the icon for the new menu.
            Dim oMenuItem As SAPbouiCOM.MenuItem = oApplication.Menus.Item(oXMLDoc.SelectSingleNode("Application/Menus/action/Menu/@UniqueID").Value)
            oMenuItem.Image = sPath & "orange.bmp"
            AddMenus = True
        Catch ex As Exception
            oApplication.MessageBox("AddMenus(): " & oCompany.GetLastErrorCode.ToString & ", " & ex.Message)
        Finally
            oForm.Freeze(False) 
        End Try
    End Function

XML menu example


<Application>
	<Menus>
		<action type="add">
			<Menu Checked="0"
				  Enabled="1"
				  FatherUID="43520"
				  String="Orange.One"
				  Type="2"
				  UniqueID="ADAT_OONE">
				<Menus>
					<action type="add">
						<Menu Checked="0"
							  Enabled="1"
							  FatherUID="ADAT_OONE"
							  String="Sair"
							  Type="1"
							  UniqueID="ADAT_OONE_mnuExit"></Menu>
					</action>
				</Menus>
				<Menus>
					<action type="add">
						<Menu Checked="0"
							  Enabled="1"
							  FatherUID="ADAT_OONE"
							  String="Calibrador"
							  Type="2"
							  UniqueID="ADAT_OONE_mnuCalibrador">
							<Menus>
								<action type="add">
									<Menu Checked="0"
										  Enabled="1"
										  FatherUID="ADAT_OONE_mnuCalibrador"
										  String="Variedades"
										  Type="1"
										  UniqueID="ADAT_OONE_mnuVariedades"></Menu>
								</action>
							</Menus>
							<Menus>
								<action type="add">
									<Menu Checked="0"
										  Enabled="1"
										  FatherUID="ADAT_OONE_mnuCalibrador"
										  String="Lotes"
										  Type="1"
										  UniqueID="ADAT_OONE_mnuLotes"></Menu>
								</action>
							</Menus>
						</Menu>
					</action>
				</Menus>
				<Menus>
					<action type="add">
						<Menu Checked="0"
							  Enabled="1"
							  FatherUID="ADAT_OONE"
							  String="Tipos de Embalamento"
							  Type="2"
							  UniqueID="ADAT_OONE_mnuPacking">
							<Menus>
								<action type="add">
									<Menu Checked="0"
										  Enabled="1"
										  FatherUID="ADAT_OONE_mnuPacking"
										  String="Dados Mestre da Caixa"
										  Type="1"
										  UniqueID="ADAT_OONE_mnuCaixa"></Menu>
								</action>
							</Menus>
							<Menus>
								<action type="add">
									<Menu Checked="0"
										  Enabled="1"
										  FatherUID="ADAT_OONE_mnuPacking"
										  String="Dados Mestre da Palete"
										  Type="1"
										  UniqueID="ADAT_OONE_mnuPalete"></Menu>
								</action>
							</Menus>
							<Menus>
								<action type="add">
									<Menu Checked="0"
										  Enabled="1"
										  FatherUID="ADAT_OONE_mnuPacking"
										  String="Dados Mestre da Embalagem"
										  Type="1"
										  UniqueID="ADAT_OONE_mnuEmbal"></Menu>
								</action>
							</Menus>
							<Menus>
								<action type="add">
									<Menu Checked="0"
										  Enabled="1"
										  FatherUID="ADAT_OONE_mnuPacking"
										  String="Dados Mestre do Calibre"
										  Type="1"
										  UniqueID="ADAT_OONE_mnuCalibre"></Menu>
								</action>
							</Menus>
						</Menu>
					</action>
				</Menus>
			</Menu>
			<Menu Checked="0"
				  Enabled="1"
				  FatherUID="43525"
				  String="Orange.One"
				  Type="2"
				  UniqueID="ADAT_OONE_SETUP">
				<Menus>
					<action type="add">
						<Menu Checked="0"
							  Enabled="1"
							  FatherUID="ADAT_OONE_Setup"
							  String="Dados Mestre da Palete"
							  Type="1"
							  UniqueID="ADAT_OONE_SETUP_mnuPalete"></Menu>
					</action>
				</Menus>
				<Menus>
					<action type="add">
						<Menu Checked="0"
							  Enabled="1"
							  FatherUID="ADAT_OONE_Setup"
							  String="Dados Mestre da Caixa"
							  Type="1"
							  UniqueID="ADAT_OONE_SETUP_mnuCaixa"></Menu>
					</action>
				</Menus>
				<Menus>
					<action type="add">
						<Menu Checked="0"
							  Enabled="1"
							  FatherUID="ADAT_OONE_Setup"
							  String="Dados Mestre da Embalagem"
							  Type="1"
							  UniqueID="ADAT_OONE_SETUP_mnuEmbal"></Menu>
					</action>
				</Menus>
			</Menu>
		</action>
	</Menus>
</Application>

Regards,

Vítor Vieira

Former Member
0 Kudos

Hi...

use this code it will work

Private Sub AddMenuItem()

Try

Dim oMenuItem As SAPbouiCOM.MenuItem

Dim oMenus As SAPbouiCOM.Menus

Dim oCreationPackage As SAPbouiCOM.MenuCreationParams

oCreationPackage = SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_MenuCreationParams)

oMenuItem = SBO_Application.Menus.Item("2304") Rem under purchase module

oCreationPackage.Type = SAPbouiCOM.BoMenuType.mt_STRING

If SBO_Application.Menus.Exists("MenuID") Then

SBO_Application.Menus.RemoveEx("MenuID")

End If

oCreationPackage.UniqueID = "SubMenu"

oCreationPackage.String = "SubMenu Name"

oCreationPackage.Enabled = True

oCreationPackage.Checked = True

oCreationPackage.Position = 0

oMenus = oMenuItem.SubMenus

oMenus.AddEx(oCreationPackage)

Catch ex As Exception

SBO_Application.MessageBox(ex.Message)

End Try

End Sub

Regards...

Billa 2007