Re: dynamic menu question
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Sat, 04 Feb 2006 21:55:22 -0500
There are again two answers:
(a) Create a popup menu at runtime and insert it into your existing menu system in the
right place
(b) Create a menu at design time and load it dynamically, then put it where needed
Note that in case (a), no menu ID is needed because a menu ID is only required to retrieve
a menu from the resource segment. If you are using CreatePopupMenu at runtime, there's no
menu to retrieve, hence, no need for a menu ID. Note that this doesn't solve the problem
of how you assign menu IDs to the items of that popup menu, which is what I was answering.
joe
On Sat, 4 Feb 2006 20:24:04 -0600, "Asser" <as@xxxxxxxxx> wrote:
probably we didn't understand each other correctly,Joseph M. Newcomer [MVP]
I'm trying to add dynamically completely new menu,(not an item in menu)
so I guess there is a way to created menu without righting in resource
editor.
"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:aolau1hb4et0nf82aqed8nja3cpdq8mm82@xxxxxxxxxx
Well, 1234 is probably a bad choice of range because it can overlap with
the range of
other controls.
Where you put it is up to you. It's just a #define.
The example is meaningless. If you define IDR_DYNA in the resource
editor, it will be
there; if you do the #define of a menu item by hand, there's no menu of
that ID there, so
it won't do anything. This does not correspond to anything you were
suggesting you needed
to do; you were asking how to create menu items; LoadMenu does not load
individual menu
items, it loads entire menus
joe
On Sat, 4 Feb 2006 01:43:08 -0600, "Asser" <as@xxxxxxxxx> wrote:
Joe,Joseph M. Newcomer [MVP]
I tried the #define method you described like this:
#define IDR_DYNA 1234
but where I actually load this resource?
in this fails -> LoadMenu(NULL, MAKEINTRESOURCE(IDR_DYNA))
.thanks
"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:pva8u15oeni5lqm6aa2notrqsehtv4n6bh@xxxxxxxxxx
There are several questions here.
First, how do you add new IDs? Well, the method I've found simplest in
a
lot of cases is
to create the ID in the dialog editor and add the menu item at design
time. Then at
runtime, delete all the items you don't need. The other solution,
particularly when you
need some open-ended (more or less) set of values not computable until
runtime, such as a
list of options which are computed based on data, environment, or
whatever, pick a range
of integers, e.g.,
#define IDR_MYMENU_FIRST 11000
#define IDR_MYMENU_LAST 11100
then as you add menu items, you just start with IDR_MYMENU_FIRST and
increment until you
get to IDR_MYMENU_LAST (at which point you have some serious decisions
to
make). If items
can go in and out, you have a set of elements indexed by the count,
increment it in a
circular fashion. When you add a menu item, add it to the set (e.g.,
CMap, or std::map),
and when you delete one, delete it from the map. An integer value is
valid if it is not
already in the map. Typically, the map would map the integer to the
information required
to interpret the item.
Next, the question is how do you respond to menu item selection for
runtime-created menus.
Use ON_COMMAND_RANGE in your message map, and the UINT delivered to the
handler is the
index into the map.
Finally, how do you maintain a menu? Note that whenever you change
views
in MDI, a new
menu is reloaded from the MENU resource, thus clobbering your menu,
which
you will have to
rebuild. I think OnActivateFrame is where you need to do this (note
that
you don't just
add items; they may still be present, so you need to deal with that.
What
I did was
delete all the dynamic menu items in the range
IDR_MYMENU_FIRST..IDR_MYMENU_LAST and then
add them back in).
joe
On Fri, 3 Feb 2006 18:48:54 -0500, "Derek" <der@xxxxxxxxx> wrote:
hi, AfxGetMainWnd gets me the main window menu, but I'm creating newJoseph M. Newcomer [MVP]
menu.
I just need find a way to give that menu IDR_ identifier somehow...
"Tom Serface" <tserface@xxxxxxx> wrote in message
news:eb6lZpRKGHA.1848@xxxxxxxxxxxxxxxxxxxxxxx
You have to get the menu item with code like:
CMenu* pMenu = AfxGetMainWnd()->GetMenu();
Then you modify the menu dynamically.
If you want change a menu you can use LoadMenu() to replace any menu
with
one from your resources.
If you trying to pop down a menu from a button this code might help
you:
http://www.codeproject.com/buttonctrl/pushmenubutton.asp
Tom
"Asser" <ass@xxxxxxxxx> wrote in message
news:%2337MgXRKGHA.1848@xxxxxxxxxxxxxxxxxxxxxxx
Hello,
this code below works if I have static menu created in resource
editor
with some IDR_ but when I create menu dynamically how do I attach new
IDR_ value to it?
HMENU m_wDynaMenu;
m_wDynaMenu = ::CreateMenu();
AppendMenu(m_wDynaMenu, MF_STRING, IDR_DYNAMENU, _T("first
entry"));
m_Button.SetMenu(IDR_DYNAMENU, CWnd::GetSafeHwnd() );
how to associate IDR_DYNAMENU with this menu?
probably I'm doing something stupid here :)
thanks
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: dynamic menu question
- From: Asser
- Re: dynamic menu question
- References:
- dynamic menu question
- From: Asser
- Re: dynamic menu question
- From: Tom Serface
- Re: dynamic menu question
- From: Derek
- Re: dynamic menu question
- From: Joseph M . Newcomer
- Re: dynamic menu question
- From: Asser
- Re: dynamic menu question
- From: Joseph M . Newcomer
- Re: dynamic menu question
- From: Asser
- dynamic menu question
- Prev by Date: Re: heeeeeeeeeeeeeeeellllllllllllllppppppppppppppppppppp
- Next by Date: Re: Plotting points
- Previous by thread: Re: dynamic menu question
- Next by thread: Re: dynamic menu question
- Index(es):