|
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
On 28/10/2006, at 7:34 PM, Rosyna wrote:
Sorry, the OSStatus I get back from SetMenuItemHierarchicalMenu() is zero.
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. 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,
//--------------------------------------------------------------------------------------------------------- // • 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 ); } 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) #define DOES_NOT_WORK void MenuTest(); bool isSpecialCommandsSubMenu(char * menustring); bool isSpecialCommandsSubMenu(char * menustring){ return (menustring[0] == 'f'); } void MenuTest() { char * menustrings[5] = {"one", "two", "three", "four", "five"}; char * submenustrings[2] = {"subone", "subtwo"}; int basemenuindex = 201; MenuRef specialmenuref; CreateNewMenu(++basemenuindex, 0, &specialmenuref); SetMenuTitleWithCFString(specialmenuref, CFSTR("Special")); InsertMenu(specialmenuref, 0); for (int mi = 0; mi < 5; ++mi) { MenuRef m1ref; CFStringRef m1string = CFStringCreateWithCString(kCFAllocatorDefault, menustrings[mi],0); CreateNewMenu(++basemenuindex, 0, &m1ref); SetMenuTitleWithCFString(m1ref, m1string); for (int smi = 0; smi < 2; ++smi) { CFStringRef m2string = CFStringCreateWithCString(kCFAllocatorDefault,submenustrings[smi],0); InsertMenuItemTextWithCFString(m1ref,m2string,0,0,0); } if (isSpecialCommandsSubMenu(menustrings[mi])) { #ifdef DOES_NOT_WORK SetMenuID(m1ref, 0); SetMenuItemHierarchicalMenu(specialmenuref, 0, m1ref); InsertMenu(m1ref, kInsertHierarchicalMenu); #else InsertMenu(m1ref, 0); #endif } else { InsertMenu(m1ref, 0); } } DrawMenuBar(); } I changed it a little bit
|
_______________________________________________ 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>) |
| Home | Archives | Terms/Conditions | Contact | RSS | Lists | About |
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.