Re: dynamic menus
- From: "Bill Brehm" <don't want any spam>
- Date: Sat, 13 Aug 2005 16:17:15 +0800
Yes, you are right about the variable going out of scope. I'm new at Windows
programming, so I keep getting tripped up by little things like this.
Thanks, I'm able to move further now.
So every menu item ID within the entire project must be unique, but it
doesn't matter if the ID is reused by a button or string or any other
control? I see the standard menu ID have a special range stating near
0xE000, so I will stay away from that. I have to be careful that I don't use
an ID that the class wizard may later assign to another menu that is not
dynamically generated. Is it safe to use WM_USER and add one for each new
dymanic menu item?
More importantly, how do I 'connect' these to OnDynamicMenuItem() and
OnUpdateDynamicMenu()? Since I am creating the menus at runtimme, I can't
depend on compile time functions. That means I would prefer to have the
entire range of these dynamic menus be 'connected' to single functions that
are passed the ID, so they can look up the correct menu object to access. I
could put the dynamic menu item along with its two functions into a class.
But I still don't know how to programmatically add the 'connection' from the
ID to the functions.
Thanks...
"David Ching" <dc@xxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:PAfLe.1308$A%3.232@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>
> "Bill Brehm" <don't want any spam> wrote in message
> news:%23sLYUF8nFHA.2904@xxxxxxxxxxxxxxxxxxxxxxx
>>I want to be able to create a hierarchy of menus under the view menu. I
>>don't know at design time how many items will be under each submenu.
>>
>> I have been able to access and add to the view menu itself. By I have not
>> been able to add anything under that added menu. I know it shuold be a
>> popup menu. but when I make it a popup, I get an assert when I try to
>> open the view menu. Here's what I have so far (some experimentation still
>> remains):
>>
>> m_pWndMenu = GetMenu();
>> //int count = m_pWndMenu->GetMenuItemCount();
>> //CString string;
>> //m_pWndMenu->GetMenuString(2, string, MF_BYPOSITION);
>> CMenu *pViewMenu = m_pWndMenu->GetSubMenu(2); // gets view menu.
>> pViewMenu->InsertMenu(0, MF_BYPOSITION | MF_SEPARATOR);
>> CMenu objectMenu;
>> objectMenu.CreateMenu();
>> pViewMenu->InsertMenu(0, MF_BYPOSITION | MF_STRING | MF_POPUP,
>> (int)objectMenu.m_hMenu, "Objects");
>> CMenu *pObjectMenu = pViewMenu->GetSubMenu(0); // gets object menu
>> pObjectMenu->InsertMenu(0, MF_BYPOSITION | MF_STRING, 101, "Object 1");
>> pObjectMenu->InsertMenu(0, MF_BYPOSITION | MF_STRING, 102, "Object 2");
>>
>> What am I doing wrong and how do I fix it?
>>
>
> Most likely your objectMenu is going out of scope and being destroyed.
> Make objectMenu a member of a class (perhaps the CWnd that owns the menu)
> that will stick around for the lifetime of the menu.
>
>
>> Also, will have to call a function and/or work with OnUpdateCmdUI(). How
>> do I dynamically create IDs for these when I won't know in advance how
>> many levels deep and how many items at each level. (I have seen duplicate
>> IDs in resource.h. But I don't know where duplicates are allowed without
>> causing a conflict.) I have looked at the dynamenu example, but they are
>> only adding into a menu that already exists and they are not creating a
>> popupmenu. Furthermore, they have predefined all their IDs because they
>> know in advance that they will support four colors.
>>
>
> Each command ID generated by the menu items must be unique. Beyond that,
> there is no restriction. Perhaps you could use a counter, initialized to
> a value greater than any of the existing menu item command id's, and
> increment it each time you add one of your own. (I think Windows restrict
> command id's to some range, so you can't use just any number.) Then you'd
> have to remember which ID was for what function, so you could properly
> handle the commands when they are selected from your menu.
>
> -- David
> http://www.dcsoft.com
>
>
.
- Follow-Ups:
- Re: dynamic menus
- From: David Ching
- Re: dynamic menus
- From: Scott McPhillips [MVP]
- Re: dynamic menus
- References:
- dynamic menus
- From: Bill Brehm
- Re: dynamic menus
- From: David Ching
- dynamic menus
- Prev by Date: ZOrder problem w/dynamically created Edit controls
- Next by Date: Re: dynamic menus
- Previous by thread: Re: dynamic menus
- Next by thread: Re: dynamic menus
- Index(es):
Relevant Pages
|