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

Creating menuitems dynaically

0 views
Skip to first unread message

Pete Mc Evoy

unread,
Aug 10, 1995, 3:00:00 AM8/10/95
to peter_d...@ccm.hf.intel.com
>I need to create menuitems dynamically. I do not know how many menu-items there will be, so


>1. Can it be done???

YES

>2. If so, How???

Windows API (ApendMenu). I can email you an example if you need it.

>3. How do I detect that the user clicked on one of these items?

map a pbm_syscommand to a user defined event on the window and handle it there

>4. How do I handle the script-problem (scrips assosiated with the new item)?

I have used the api to play with the system menus on windows, this is the only way
to control them (that powerbuilder provides). But I already knew the actions I
wanted to perform. What I'm getting at is that in Powerbuilder you need to know in
advance how you are going to respond to an event, you can't dynamically send code to
the compiler (like in other interpretive languages. So, if you already have scripts
then I recommend either hide/display the menu items or a gigantic case statement in
the syscommand of the window. You could then call functions which would effectively
be the scripts.


Good Luck
Pete Mc Evoy
Intel

Mark Lebar

unread,
Aug 10, 1995, 3:00:00 AM8/10/95
to
In article <40dl89$8...@mn5.swip.net>,
Claes...@mailbox.swipnet.se (Claes Wedin) wrote:
>Please Help me!

>I need to create menuitems dynamically. I do not know how many menu-items
there will be, so
>I cannot use predefined items and then hide/show them. I really want to
expand the menu
>during execution. Questions:

>
>1. Can it be done???
>2. If so, How???

>3. How do I detect that the user clicked on one of these items?
>4. How do I handle the script-problem (scrips assosiated with the new item)?
>
>Claes Wedin, PRIMO System AB, Sweden
>
>PS!
>I would really like some comments on this! Even comments like "it cannot be
done" would help
>me proceed with my problem. I am completely stuck into my little corner!!
>
>
>
>
>

I am not sure if this can be done. Somehow I don't think
so but I haven't delved deeply into the matter. However,
you say that you don't know how many items that you will
have so you don't want to use predefined menuitems... why
not? Why not just determine the conceivable maximum and
make that many items. Make them all hidden by default, and
change the names and visibility as you need them.

I am sure that there must also be a finite number of scripts.
So why not have a bunch of dummy invisible menu items, and
trigger them as you need them?


Mark

--------------------------
Mark Lebar
VytalNet Inc.
Ma...@VytalNet.com
--------------------------

Claes Wedin

unread,
Aug 10, 1995, 3:00:00 AM8/10/95
to
Regarding my problems with dynamically changing menuitems...

I tried to mail the following directly to Pete, who responded very quick to my help-call, but it
came back to me. Therefore I have to try this way to deliver my message to you.


Pete!

Thanks for the very fast respond on my problems with dynamically changing menuitems!
You said you could email me an example. Please do, because I think it would help me.

My email adress is Claes...@mailbox.swipnet.se

Once again, many thanks!!

Claes


Claes Wedin

unread,
Aug 10, 1995, 3:00:00 AM8/10/95
to

Manish Shah

unread,
Aug 11, 1995, 3:00:00 AM8/11/95
to
Your problem seems suitable for a list box rather than
menus. May be you should consider a list box where # of items can be
unlimited and dynamic. Problem with adding PB menu items dynamnically
is that it has code and variables attached to it. Windows itself
does not have code etc attached to the menus. There for you may be able
to show additional menu items with a call to SDK function and
handling the message in 'Other' event when they are clicked.

Manish Shah - Toronto Canda


Dave Berthiaume

unread,
Aug 11, 1995, 3:00:00 AM8/11/95
to Claes...@mailbox.swipnet.se
There is an article in the latest issue of PowerSource that directly
addresses your problem. I suggest you pickup a copy. Basically, you
need to setup some external Windows API functions, then create a user
event on the menu's window to handle scripts for the new menu item. Good
luck!

Dave Berthiaume, CPD Professional

Anna Balayn

unread,
Aug 16, 1995, 3:00:00 AM8/16/95
to
Claes Wedin (Claes...@mailbox.swipnet.se) wrote:
: Please Help me!


I implemented a dynamic menu and I will describe how I did it but before that
I must say that the application is not in production yet so I don't know if
there will be any problems with my solution.

This is how I did it:

1. Let's say I have an item m_profiles in my top-level menu m_main.
2. I then defined a menu m_dynamic with one item m_item. m_item has a script
which does whatever those dynamic items should do.
3. In the window script which is supposed to create a new menuitem I put
the following code:

menu m_current
m_dynamic m_new

m_current = this.menuid
m_new = create m_dynamic

m_new.m_item.text = "whatever"
m_new.m_item.tag = "....."
....

m_current.m_profiles.item[UpperBound(m_current.m_profiles.item)+1] = &
m_new.m_item

m_current.hide()
m_current.show()

The last two lines will redraw the menu.

The only problem I found (and I still have to figure out a way around it) is
that if the dynamic menuitem has an instance variable or a function then I
can't access it later because I don't keep reference to m_dynamic (it's a local
variable m_new)

You could also have an event in the window with all the code for the new item
in there and have the menuitem trigger the event.



BK

unread,
Aug 21, 1995, 3:00:00 AM8/21/95
to
an...@ilx.com (Anna Balayn) wrote:
>This is how I did it:

>1. Let's say I have an item m_profiles in my top-level menu m_main.
>2. I then defined a menu m_dynamic with one item m_item. m_item has a script
> which does whatever those dynamic items should do.
>3. In the window script which is supposed to create a new menuitem I put
> the following code:
> menu m_current
> m_dynamic m_new
> m_current = this.menuid
> m_new = create m_dynamic
> m_new.m_item.text = "whatever"
> m_new.m_item.tag = "....."
> ....
> m_current.m_profiles.item[UpperBound(m_current.m_profiles.item)+1] = &
> m_new.m_item

> m_current.hide()
> m_current.show()

Okay, now that this was done (which I am happy it can be done!! :) ),
how do you attach script for this new menu item?? I need it to either
post a window event or somehow run a function or anything. I just
need it to run some kind of script??

I was going to use an API call and I started using CreateMenu and
CreatePopUpMenu and either SetMenu or TrackPopUpMenu, but to no avail.
How can I do this either on the C++ level or, preferably, on the PB
level??!?!?!!?

-bk


0 new messages