Print Page | Close Window

MenuBarMDIMenus Item takes what?

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=7944
Printed Date: 18 June 2025 at 7:48am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: MenuBarMDIMenus Item takes what?
Posted By: cradke
Subject: MenuBarMDIMenus Item takes what?
Date Posted: 05 September 2007 at 2:02pm
What should be passed to the Item property of the MenuBarMDIMenus collection.  Nothing seems to work.  Using the CommandBars\VB\MDISample none of the following attempts work.
 
    Dim MDIMenus As MenuBarMDIMenus
    Set MDIMenus = CommandBars.ActiveMenuBar.MDIMenus
    Dim MDIMenu As MenuBarMDIMenu
    Set MDIMenu = MDIMenus.Add(100, "Document", "Document")
    Set MDIMenu = MDIMenus.Add(101, "Image", "Image")

    Set MDIMenu = MDIMenus.Item(100)
    Set MDIMenu = MDIMenus.Item(1)
    Set MDIMenu = MDIMenus.Item(0)
    Set MDIMenu = MDIMenus.Item("Document")

In fact the following code never displays a message box
 
    Set MDIMenu = Nothing
    On Error Resume Next
    Dim Index As Long
    For Index = 0 To 65535
        Set MDIMenu = MDIMenus.Item(Index)
        If Not MDIMenu Is Nothing Then
            MsgBox MDIMenu.Caption + " " + CStr(Index)
        End If
    Next Index
 
The documentation says it should be the Id of the MDIMenu but the Id does not work.  This in and of itself is strange since the other collections take the standard 1 based index.   Using the Id makes it difficult to enumerate the list using the Item property since every part of the application must know in advance what the Id's are.
 
Chris Radke
 
 



Replies:
Posted By: Oleg
Date Posted: 05 September 2007 at 2:34pm
Hello,
 
Thanks, you are right. Item propety doesn't work :( Fixed for 11.2 release.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: cradke
Date Posted: 05 September 2007 at 2:54pm
I look forward to the fix, in the mean time I have an acceptable work-around by getting the IEnumVARIANT interface...
 
inline IEnumVARIANT* GetNewEnum(IDispatch* pIDispatch)
{
    IUnknown* pUnk = NULL;
    _com_dispatch_method(pIDispatch, DISPID_NEWENUM, DISPATCH_PROPERTYGET, VT_UNKNOWN, (void*)&pUnk, NULL);
    return CComQIPtr<IEnumVARIANT>(pUnk).Detach();
}
 
 
XtremeCommandBars::ICommandBar* GetMenuBarById(long MenuBarId)
{
    CComPtr<IMenuBarMDIMenus> pIMDIMenus = m_spCommandBars->GetActiveMenuBar()->GetMDIMenus();
    CComPtr<IEnumVARIANT> pIEnum(GetNewEnum(pIMDIMenus));
    if(pIEnum)
    {
        long nCount = pIMDIMenus->GetCount();
        CComVariant* pVariants = new CComVariant[nCount];
        ULONG Fetched = 0;
        HRESULT hr = pIEnum->Next(nCount, pVariants, &Fetched);
        if(SUCCEEDED(hr))
        {
            for(long Index = 0; Index < nCount; Index++)
            {



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net