>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
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
--------------------------
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
Manish Shah - Toronto Canda
Dave Berthiaume, CPD Professional
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.
>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