Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Modifying a popup menu name

0 views
Skip to first unread message

jw

unread,
Oct 25, 2004, 2:56:05 PM10/25/04
to
I can manipulate a menuitem at will. But I can't find anyway to
change the name of the popup name during runtime.
Let me explain. I have the following across the menu bar:
File Edit Tools/Aids Reports Help
Each with a series of menuitems.
I would like to change Tools/Aids to Tools at run time. The rc file
doesn't allow me to give the popups identifiers. And I've googled and
couldn't find any references.

Thanks,
JW


Tim Robinson

unread,
Oct 25, 2004, 3:09:36 PM10/25/04
to

You have to do it by position. Pass MF_BYPOSITION in the flags
parameter, and use an index (0, 1, 2, ...) instead of an ID.

--
Tim Robinson (MVP, Windows SDK)
http://mobius.sourceforge.net/

r_z_...@pen_fact.com

unread,
Oct 25, 2004, 3:19:14 PM10/25/04
to

I don't think I've ever actually tried to change the text of a popup.
But from bits and pieces of my experience, I _think_ the following is
appropriate. It assumes you're targeting "big" Windows, rather than
Windows CE; this seems a good assumption given the newsgroup.

If you're using ::SetMenuItemInfo (in Win 32 API), then I suspect
you're using the wrong value for HMENU (the first argument). If the
popup is in the top menu, then you need to use the value you get from
hMenu = ::GetMenu( hWndParent )
where "hWndParent" is the HWND for the parent dialog box. Otherwise,
you need to use the value from
hMenu = ::GetSubMenu( hMenuTop, nPos );
where "hMenuTop" is the HMENU for the parent menu. I think if I try to
clarify, I will only muddy, so I will stop here.

>
>Thanks,
>JW
>

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
500 Harrison Ave., Suite 3R
Boston, MA 02118
www.penfact.com

David Liebtag

unread,
Oct 25, 2004, 3:35:00 PM10/25/04
to
You can use ModifyMenu with the MF_BYPOSITION flag.

jw

unread,
Oct 25, 2004, 5:32:07 PM10/25/04
to

"Tim Robinson" <tim.gaat.fre...@nowhere.com> wrote in message
news:2u51b6F...@uni-berlin.de...

Thanks Tim,
The example I gave was a simple one. In real life the menuitems
change during run time in such a way that I'm afraid I might not be
smart enough to keep count. Is there a way to get menu item
information from the position so I could search for the title and then
change it.
Something like:
for(i=0;i<no_of_menu_items;i++)
{
if(strcmp(String = GetMenuItem(........,i),"Menu I'm Looking For")
== 0) //where i is the MF_BYPOSITION
{
ModifyMenu(........"New Menu Title",i);
break;
}
}
}

Thanks
JW


Tim Robinson

unread,
Oct 25, 2004, 6:28:20 PM10/25/04
to
jw wrote:
> The example I gave was a simple one. In real life the menuitems
> change during run time in such a way that I'm afraid I might not be
> smart enough to keep count. Is there a way to get menu item
> information from the position so I could search for the title and then
> change it.
[...]

No, the only options are by position, or by ID. Given that the only
thing modifying the menu is your code, the assumption is that your code
is clever enough to keep track of the modifications.

jw

unread,
Oct 25, 2004, 8:40:14 PM10/25/04
to

"Tim Robinson" <tim.gaat.fre...@nowhere.com> wrote in message
news:2u5cvpF...@uni-berlin.de...

Thanks Tom,

The code is pretty clever, unfortunately I'm the problem.

JW


jw

unread,
Oct 25, 2004, 11:01:14 PM10/25/04
to

"jw" <j...@unearthly.net> wrote in message
news:O1hfd.11564$5O4.3492@trnddc07...

For anyone that is in the same boat as me and is interested in this
subject. The MF_BYPOSITION only includes the Popup menu items. In
other words you do not count the MenuItems under the popups in the
count for the position.
Which for my problem makes the it trivial. I thought I had to keep
track of all of the MenuItems.

Thanks again everyone.

JW


Severian

unread,
Oct 26, 2004, 1:09:43 AM10/26/04
to
On Tue, 26 Oct 2004 00:40:14 GMT, "jw" <j...@unearthly.net> wrote:

>
>"Tim Robinson" <tim.gaat.fre...@nowhere.com> wrote in message
>news:2u5cvpF...@uni-berlin.de...
>> jw wrote:
>> > The example I gave was a simple one. In real life the menuitems
>> > change during run time in such a way that I'm afraid I might not
>be
>> > smart enough to keep count. Is there a way to get menu item
>> > information from the position so I could search for the title and
>then
>> > change it.
>> [...]
>>
>> No, the only options are by position, or by ID. Given that the only

>> thing modifying the menu is your code, the assumption is that yourffffffffffff


>code
>> is clever enough to keep track of the modifications.
>>
>> --
>> Tim Robinson (MVP, Windows SDK)
>> http://mobius.sourceforge.net/
>
>Thanks Tom,
>
>The code is pretty clever, unfortunately I'm the problem.

This C function returns the HMENU of a sub-menu with a specific name,
and could be easily modified to return its position (by just returning
i); however, you will have to take into account the varying names you
plan to give them!

If you always reload your menu from the resource before you modify it,
you could just use the original name, thus avoiding having to track
changes.

strcmpnoamper() compares strings without regard to case or
underscore-producing ampersands.

HMENU WINAPI FindSubMenu(HMENU hmenu, LPCTSTR name)
{
int i, c;
TCHAR text[100];
if (!hmenu)
return NULL;
c = GetMenuItemCount(hmenu);
for (i=0; i<c; i++) {
if (GetMenuString(hmenu, i, text, sizeof(text), MF_BYPOSITION)
&& !stricmpnoamper(name, text) )
return GetSubMenu(hmenu, i);
}
return NULL;
}

When you internationalize your app, you will have a new issue
(synching the string code in the source with the menu resource.)

--
Sev

jw

unread,
Oct 26, 2004, 9:15:52 AM10/26/04
to

"Severian" <seve...@chlamydia-is-not-a-flower.com> wrote in message
news:7emrn0d5oslfu3ro2...@4ax.com...

Thanks Sev,

This will certainly get filed away as a handy bit of code.
Fortunately, since I am only interested in changing the top row of
popups, ie File, Edit, Tools, etc. I can use the MF_BYPOSITION without
needing to keep track. I was surprised to find that the MF_BYPOSITION
is only counting these. In other words if I want to change the name
of the Tools popup the MF_BYPOSITION would be 2, even though there are
up to 24 menu items between File and Tools. I would have thought it
would have counted all of the menu items as well as the popups. I
really need to look at the API so I won't get surpassed if it runs
differently on 98 or 95.

JW


r_z_...@pen_fact.com

unread,
Oct 26, 2004, 3:17:43 PM10/26/04
to
On Tue, 26 Oct 2004 13:15:52 GMT, "jw" <j...@unearthly.net> wrote:

>
>"Severian" <seve...@chlamydia-is-not-a-flower.com> wrote in message
>news:7emrn0d5oslfu3ro2...@4ax.com...
>> On Tue, 26 Oct 2004 00:40:14 GMT, "jw" <j...@unearthly.net> wrote:
>>

clip

>
>This will certainly get filed away as a handy bit of code.
>Fortunately, since I am only interested in changing the top row of
>popups, ie File, Edit, Tools, etc. I can use the MF_BYPOSITION without
>needing to keep track. I was surprised to find that the MF_BYPOSITION
>is only counting these. In other words if I want to change the name
>of the Tools popup the MF_BYPOSITION would be 2, even though there are
>up to 24 menu items between File and Tools. I would have thought it

I, perhaps naively, assume that the position referred only to items in
the current level. So code that manipulates items on the top level
counts only items on the top level, and code that manipulates a
submenu counts only items in that submenu. I can't say I've tested
extensively or used many variations. But I know I often manipulate
top-level menu items (popups and buttons). In particular, I've added
and subtracted a few. And I find top-level popups so I can manipulate
their subitems. My code definitely works on 98, NT, 2K, XP, and
several versions of CE.

For items on submenus, I usually (probably always) use item ID. So I'm
not quite so sure about positions within submenus.

Tim Robinson

unread,
Oct 26, 2004, 4:47:33 PM10/26/04
to
jw wrote:
> For anyone that is in the same boat as me and is interested in this
> subject. The MF_BYPOSITION only includes the Popup menu items. In
> other words you do not count the MenuItems under the popups in the
> count for the position.
> Which for my problem makes the it trivial. I thought I had to keep
> track of all of the MenuItems.

This makes sense when you consider that the menu APIs operate on
individual menus, where a menu is not only the things that pop up, but
also the strip across the tops of windows. They don't act recursively;
if you *did* want this behaviour, you'd have to recurse into each
submenu yourself.

jw

unread,
Oct 26, 2004, 7:00:42 PM10/26/04
to

"Tim Robinson" <tim.gaat.fre...@nowhere.com> wrote in message
news:2u7relF...@uni-berlin.de...

Just for fun how would change the name of a popup that is under a
popup. For example:

File Edit Tools Reports Help

Under the Tools are

Tool1
Tool2
ToolPopUP //This is a popup
Subtool1
Subtool2
Tool3

How would I change the ToolPopUP to JimsPopUP using ModifyMenu?
Do I somehow get the handle of the Tools menu, say hToolsMenu and then
use that as the first argument of ModifyMenu and then the position of
ToolPopUP would be 3 with the MF_BYPOSITION?

JW

Tim Robinson

unread,
Oct 26, 2004, 7:29:15 PM10/26/04
to
jw wrote:
> Just for fun how would change the name of a popup that is under a
> popup. For example:
>
> File Edit Tools Reports Help
>
> Under the Tools are
>
> Tool1
> Tool2
> ToolPopUP //This is a popup
> Subtool1
> Subtool2
> Tool3
>
> How would I change the ToolPopUP to JimsPopUP using ModifyMenu?
> Do I somehow get the handle of the Tools menu, say hToolsMenu and then
> use that as the first argument of ModifyMenu and then the position of
> ToolPopUP would be 3 with the MF_BYPOSITION?

Right, you'd use a suitable arrangement of GetSubMenu and ModifyMenu.

0 new messages