Is it possible to add ..

WishmanWishman Member Posts: 36
Hi all,

I want to add a new menu item to the Tools menu.Under the language over object designer..

Is it possible, if yes how?

Any info will be appreciated.
Thanks a lot.

Comments

  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    The top menu (File, Edit, View, Tools, etc.) cannot be modified using Navision C/AL Code. This menu is defined in the fin.stx file that resides in the Navision application folder, but only MBS can modify this file to add/change menu items.
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • janpieterjanpieter Member Posts: 298
    ehm, if you really badly want it and if youre a little handy writing ActiveX DLL's in visual basic and API programming, have a look at this code:
    Public Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
    Public Declare Function GetMenu Lib "user32" (ByVal hWnd&) As Long
    Public Declare Function InsertMenu Lib "user32" Alias "InsertMenuA" (ByVal hMenu&, ByVal nPosition&, ByVal wFlags&, ByVal wIDNewItem&, ByVal lpNewItem$) As Long
    Public Declare Function GetActiveWindow Lib "user32" () As Long
    Public Declare Function AppendMenu& Lib "user32" Alias "AppendMenuA" (ByVal hMenu&, ByVal wFlags&, ByVal wIDNewItem&, ByVal lpNewItem$)
    Public Declare Function CreatePopupMenu Lib "user32" () As Long
    Public Declare Function DrawMenuBar Lib "user32" (ByVal hWnd&) As Long
    Public Declare Function GetFocus Lib "user32" () As Long
    Public Declare Function GetForegroundWindow Lib "user32" () As Long
    
    ublic Const MF_BYCOMMAND& = &H0&
    Public Const MF_BYPOSITION& = &H400&
    Public Const MF_POPUP& = &H10&
    Public Const MF_STRING& = &H0&
    Public Const MF_CHECKED = &H8&
    Public Const MF_DISABLED = &H2&
    Public Const MF_MENUBARBREAK = &H20&
    Public Const MF_MENUBREAK = &H40&
    Public Const MF_SEPARATOR = &H800&
    
    Public Sub CreateNavMenu(ByVal Name As String, ByVal SubItems As String)
        ' get parent form hwnd
        Dim hWnd As Long
        Dim oldhwnd As Long
        hWnd = GetForegroundWindow
        While hWnd <> 0
            oldhwnd = hWnd
            hWnd = GetParent(hWnd)
        Wend
        hWnd = oldhwnd
        
        ' set menu
        Dim hMenu As Long
        Dim appHMen As Long
        hMenu = CreatePopupMenu()
        
        Dim myitems() As String
        myitems = Split(SubItems, ",")
        Dim i As Integer
        For i = 0 To UBound(myitems)
            If myitems(i) <> "-" Then
                AppendMenu hMenu, MF_STRING, i, myitems(i)
            Else
                AppendMenu hMenu, MF_SEPARATOR, 0, "-"     'If you want to add saperator then unComment this line
            End If
        Next i
        
        appHMen = GetMenu(hWnd)
        InsertMenu appHMen, 5, MF_BYPOSITION Or MF_POPUP, hMenu, Name
        DrawMenuBar appHMen     'Draw Menu bar to visible menu
    End Sub
    

    And this code only appends the menu, to know if the user clicked it you will need to subclass the menu. Then you can raise an trigger in C/AL and have C/AL code executed.

    But, it all is a bit tricky and also keep in mind that Navision refreshes its menu regulary so your menu will disappear then. When navision refreshes its menu you need to refresh yours as well ..

    Oh, and you asked how you could add a menu to an existing. This is also possible but don't have a code example ready but with this code youre close ..

    Good luck :lol:
    In a world without Borders or Fences, who needs Windows and Gates?
Sign In or Register to comment.