Hi,

I am having problems removing a menu (NNTP Newsgroup Actions).

I can successfully delete all the menu items below this menu but then when
I then try to delete the menu itself, using the Delete method of the
GWMenu object, no error is raised but the menu remains visible in the
client.

An overview of how my C3PO works:
- Read a text file containing the menu items to be removed. This is
performed during the Init function of the CommandFactory. A menu item is
specified by the full 'path' e.g. Actions|NNTP Newsgroup Actions|New
Discussion. The menu items are stored in a (globally declared) Scripting
dictionary object.

- In the CustomiseMenu function I call a procedure to iterate through the
menu items to be removed. Beginning with the top level menu object, the
code drills down the menu path identifying each menu level. If the menu
item is found, the menu type is determined (i.e. GWMenu or GWMenuAction)
and an appropriate object is instantiated and the Delete method called. I
have pasted the functions below.

- The CustomizeMenu function returns False so that the changes are not
volatile and applied the first time an instance of a context is created.
(Assume that the menus are removed regardless of the context.)

Can anyone suggest what I am doing wrong?

Many thanks in advance,

Andy

My environment:
GroupWise client version: 7.0.2 (6/4/2007)
Dev Language VB6 SP6
OS: Windows XP

Public Function CustomizeMenu(sGWContext As String, objGWMenu As Object)
As Boolean
'
'The changes are not volatile.
CustomizeMenu = False
'
'Remove the menu items listed in the global dictionary object:
gdicMenuItems.
Call UpdateLogFile("")
Call UpdateLogFile("")
Call
UpdateLogFile("*********************************** *************************************")
Call UpdateLogFile("*")
Call UpdateLogFile("* CustomizeMenu Called for Context: " & sGWContext)
Call UpdateLogFile("*")
Call
UpdateLogFile("*********************************** *************************************")
Call UpdateLogFile("")
'
Call RemoveMenus(objGWMenu)
'
End Function


Private Sub RemoveMenus(ByRef objTopMenu As Object)
'
'This procedure goes through the list of menu items stored in the global
dictionary object: gdicMenuItems
'and if they exist, the item is deleted.
'
'A typical entry in the dictionary object is "File|New|Document Version"
'
'The last component in the menu item path is the menu item that is deleted.
'
Dim objMenu As Object
Dim objGWMenuAction As C3POTypeLibrary.IGWMenuAction
Dim objGWMenu As C3POTypeLibrary.IGWMenu
Dim varFullMenuPath As Variant ' Menu path found in dictionary
object. e.g. "File|New|Document Version"
Dim strFullMenuPath As String ' The full menu path as a string.
Dim arrFullMenuPath() As String ' Menu path as an array, split by the
'|' character.
Dim strMenuItemName As String ' Menu path element e.g. File or New
or Document Version.
Dim lngMenuItemIdx As Long ' Loop index for drilling down the
menu path.
Dim blnMenuFound As Boolean ' Flag indicating whether the menu was
found.
Dim strMsgTxt As String ' Message box text.
'
On Error Resume Next
'
Call UpdateLogFile("RemoveMenus Procedure Started.")
Call UpdateLogFile("")
'
'Go through all the menus to be removed.
For Each varFullMenuPath In gdicMenuItems
'
'Convert the variant object representing the full menu path into a
string.
strFullMenuPath = CStr(varFullMenuPath)
Call UpdateLogFile("Strip the menu item: " & strFullMenuPath & ".")
'Split the menu into its component parts.
arrFullMenuPath = Split(CStr(varFullMenuPath), "|")
'
'Set the Menu object to represent the top level menu.
Set objMenu = objTopMenu
'
'Assume the menu can not be found.
blnMenuFound = False
'
'Drill down the menu path.
For lngMenuItemIdx = LBound(arrFullMenuPath) To UBound(arrFullMenuPath)
strMenuItemName = arrFullMenuPath(lngMenuItemIdx)
'Set the Menu item object to be the desired child menu item.
Set objMenu = objMenu.MenuItems.Item(strMenuItemName)
Select Case Err.Number
Case 0
' The child menu item was found.
Call UpdateLogFile(String(lngMenuItemIdx, vbTab) & "Found
menu item: '" & strMenuItemName & "'.")
blnMenuFound = True
Case 91
' The menu does not exist - therefore it does not have to
be removed.
Err.Clear
Call UpdateLogFile(" * Unable to find the menu item: '" &
strMenuItemName & "' as part of: " & strFullMenuPath & " in this context.")
blnMenuFound = False
Exit For
Case Else
strMsgTxt = "* An unexpected error was raised in the
'RemoveMenus' procedure when attempting to " & _
"instantiate an object representing a menu." &
vbCrLf & vbCrLf & _
"The full menu path was: " & strFullMenuPath & vbCrLf
& vbCrLf & _
"The menu item name was '" & strMenuItemName & "'." &
vbCrLf & vbCrLf & _
"The error number was " & Err.Number & " with the
description:" & _
vbCrLf & vbCrLf & Err.Description & vbCrLf & vbCrLf &
cstrHelp
Call UpdateLogFile(strMsgTxt)
MsgBox strMsgTxt, vbExclamation, cstrAppTitle
Err.Clear
blnMenuFound = False
Exit For
End Select
Next lngMenuItemIdx
'
'If the menu item was found, try to delete it.
If blnMenuFound = True Then
Call UpdateLogFile("Menu Identified: " & strFullMenuPath & ".
Caption: " & objMenu.Caption)
' If the menu has previously been stripped, the objMenu object may
be 'Nothing'.
' In this case, do not attempt to remove it.
Call UpdateLogFile("The menu type: " & TypeName(objMenu))
If TypeName(objMenu) = "Nothing" Then
Call UpdateLogFile("* The menu type is 'Nothing' therefore the
menu no longer exists in this context.")
Else
Call UpdateLogFile("Stripping the menu ...")
Select Case objMenu.ObjType
Case C3POTypeLibrary.GWOBJTYPE.eGW_GWMENUACTION
Set objGWMenuAction = objMenu
If Err.Number <> 0 Then
Call UpdateLogFile("* Failed to set a GW Menu
Action type object to this menu. Err Number: " & Err.Number)
Call UpdateLogFile(Err.Description)
Err.Clear
Else
objGWMenuAction.Delete
If Err.Number <> 0 Then
Call UpdateLogFile("* Failed to delete a GW
Menu Action type object. Err Number: " & Err.Number)
Call UpdateLogFile(Err.Description)
Err.Clear
Else
Call UpdateLogFile("Stripped the action menu
item: " & strFullMenuPath & ".")
End If
End If
Case C3POTypeLibrary.GWOBJTYPE.eGW_GWMENU
Set objGWMenu = objMenu
Call UpdateLogFile("The GW Menu has " &
objGWMenu.MenuItems.Count & " sub menu items.")
Call UpdateLogFile("The GW Menu Parent: " &
objGWMenu.Parent.Caption)
If Err.Number <> 0 Then
Call UpdateLogFile("* Failed to set a GW Menu type
object to this menu. Err Number: " & Err.Number)
Call UpdateLogFile(Err.Description)
Err.Clear
Else
objGWMenu.Delete
If Err.Number <> 0 Then
Call UpdateLogFile("* Failed to delete a GW
Menu type object. Err Number: " & Err.Number)
Call UpdateLogFile(Err.Description)
Err.Clear
Else
Call UpdateLogFile("Stripped the menu item: "
& strFullMenuPath & ".")
End If
End If
End Select
End If
End If
'
Next ' Next (full) menu path.
'
Set objMenu = Nothing
Set objGWMenuAction = Nothing
Set objGWMenu = Nothing
'
End Sub