Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Submenu woes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Submenu woes



Title: Re: Submenu woes
Ack, at 10/28/06, David Walters said:

I'm afraid I'm a little slow on the uptake with your answer, and I tried passing a 0 to every function that required a menuID - but I couldn't get it to run.

That's because SetMenuItemHierarchicalMenu() doesn't take a menu id. It takes a MenuItemIndex, you're passing 0, which isn't a valid index in this case.

Notice the text you quoted from the Menu Manager Reference and the sample code you pasted. The sample code correctly passes an index (4). The index is the menu item you want to attach the submenu to.


First, I make a new project : a Carbon C++ Application
Then I open main.cpp, and I paste the code I sent the list before, (or the latest version which is below) - at line 13,
and I add a line at MainWindow::Create (which is now line 80), calling the new function.

MenuTest();

One thing I can tell you is that if you do it this way, you need to set up your windows etc before you instantiate your MainWindow class.

So
        MenuTest();
goes above
        MainWindow* wind = new MainWindow();

If you don't, you will get no menus and no explanation!

I press command-y, the project compiles and begins debugging, the window appears, and the menuitems entered at root level work as expected, I click them and down drops a submenu. That works.

        (screenshot removed in the name of netiquette)

Yet, for some strange reason, the "Special Menu" does not work as I have assumed in the code, based on a Carbon app I got from Apple, called Menu Views - ( http://developer.apple.com/samplecode/MenuViews/listing5.html )

        (screenshot removed, but I have it if you need proof that i can run it without errors)
In the picture above, I have clicked the "Special" menu, and nothing dropped down, rather disappointingly :(


FYI,

Discussion
Using SetMenuItemHierarchicalMenu, it is possible to directly specify the submenu for a menu item without specifying its menu ID. It is not necessary to insert the submenu into the hierarchical portion of the menubar, and it is not necessary for the submenu to have a unique menu ID. Simply use 0 as the menu ID for the submenu, and identify selections from the menu by command ID.
(from the Menu Manager Reference, ADC Oct 06) - SetMenuItemHierarchicalMenu

//---------------------------------------------------------------------------------------------------------
//      * CreateSubmenus
//      Creates some sample submenus.
//---------------------------------------------------------------------------------------------------------
static void CreateSubmenus( MenuRef topMenu, int count )
{
        int             i;
        MenuRef menu = topMenu;
       
        for ( i = 1; i <= count; i++ )
        {
                MenuRef submenu;
               
                DuplicateMenu( topMenu, &submenu );
                SetMenuItemHierarchicalMenu( menu, 4, submenu );
                menu = submenu;
        }
       
        // clear the submenu link in the bottom-most menu (which otherwise will point to the first submenu)
        SetMenuItemHierarchicalMenu( menu, 4, NULL );
}

from http://developer.apple.com/samplecode/MenuViews/listing5.html

Here is a slightly different, but not working, version of the generic menu maker... this is what I pasted into line 13 of main.cpp (I didn't do anything else to the boilerplate c++ application that xcode built for me)

--


Sincerely,
Rosyna Keller
Technical Support/Carbon troll/Always needs a hug

Unsanity: Unsane Tools for Insanely Great People

It's either this, or imagining Phil Schiller in a thong.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Submenu woes (From: David Walters <email@hidden>)
 >Re: Submenu woes (From: Rosyna <email@hidden>)
 >Re: Submenu woes (From: David Walters <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.