Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable / disable a shortcutmenu

Status
Not open for further replies.

RedLion

Programmer
Sep 13, 2000
342
NL
Hello,

To disable a menu is working, by

SET SKIP OF BAR 3 OF Record .T.

Record is a menu level of my main menubar, and I disable item 3.

until here everything works just fine.

Now I've got a shortcut menu for the rightmouseclick named smTest, and I would like to disable item 2 of it, how should I do that? It's a simple thing, but I can't get it work.


thanx,

Charl [sig][/sig]
 
Hi Charl,

how should I do that?

It works the same way, once you have your shortcut menu defined in memory.

SET SKIP OF BAR 2 OF smTest .T.

It's a simple thing, but I can't get it work.

Make sure there isn't a SKIP FOR condition when you defined your menu bar.
Example:
DEFINE BAR 2 OF smTest PROMPT "Test" SKIP FOR oApp.ilBusy

If so, this would always take precendence over SET SKIP OF BAR 2 OF smTest .T. [sig]<p>Jon Hawkins<br><a href=mailto: jonscott8@yahoo.com> jonscott8@yahoo.com</a><br><a href= > </a><br>Focus on the solution....Not the problem.[/sig]
 
Hello Jon,

Sorry but doesn't work. I also tought that it should by SET SKIP OF BAR 2 OF smTest .T. but the problem is it doesn't reconise the name of the shortcutmenu.
When I use ?MRKBAR('smTest', 1)to test if it reconises the shortmenu I get the error:

Menu has not defined with popup!

What I've done to create the shormenu:
In the Project Manager - Other - New - Shortcut
added 2 items, 1 = Red, 2 = Blue I saved it as smTest.mnx and generate it.

In the rightclick event of formMain I've put the code

DO smTest.mpr

in the click of a button on the formMain I've put the code:

SET SKIP OF BAR 2 OF smTest .T.

It seems that the name I call the 'set skip' is wrong?

Can the problem be that the menu only exist after a right click, should I load it with the Init of the form and than hide it at someway???????

Strange........

Thanx,

Charl [sig][/sig]
 
Ok. I see the problem now.

Menu has not defined with popup!

By default, the menu builder names the menu shortcut and not smTest when generated.

Open the .Mpr file with MODI COMM smTest.Mpr and change the name of your menu to smTest.

FWIW, I would move the menu definition into a .prg file. [sig]<p>Jon Hawkins<br><a href=mailto: jonscott8@yahoo.com> jonscott8@yahoo.com</a><br><a href= > </a><br>Focus on the solution....Not the problem.[/sig]
 
Jon, menu and popup are completely different objects in memory and have completely different names. Manu builder usually uses unique-generated names for popups in mpr file. So your words should be:

Open the .Mpr file with MODI COMM smTest.Mpr and change the name of your popup to smTest.


[sig]<p>Vlad Grynchyshyn<br><a href=mailto:vgryn@softserve.lviv.ua>vgryn@softserve.lviv.ua</a><br>[/sig]
 
Yes Jon, your right, only what do you mean with MODI COMM, how can I change the name?

I've taken notepad, and replaced 'shortcut' by 'smTest', but when I re-generate the menu, VFP replaces all 'smTest' by 'shortmenu', what to do?

All most solved the problem......... :)

Thanks Jon,

Charl [sig][/sig]
 
MODI COMM

Type: MODIFY COMMAND smTest.Mpr in the VFP Command Window.
Or you can use notepad, both have the same result.

I've taken notepad, and replaced 'shortcut' by 'smTest', but when I re-generate the menu, VFP replaces all 'smTest' by 'shortmenu', what to do?

There is no need to regenerate the menu. Generation only produces the code necessary to define the menu. [sig]<p>Jon Hawkins<br><a href=mailto: jonscott8@yahoo.com> jonscott8@yahoo.com</a><br><a href= > </a><br>Focus on the solution....Not the problem.[/sig]
 
Hi Vlad,

Jon, menu and popup are completely different objects in memory and have completely different names

Agreed.

Manu builder usually uses unique-generated names for popups in mpr file

This is true when using the menu builder to generate a menu. However, when using the menu builder to generate a shortcut menu, the builder assigns the popup menu the name shortcut. Try it. :)

So your words should be:

I stand by my choice of words. DEFINE MENU creates a menu bar, DEFINE POPUP creates a menu, DEFINE PAD creates a menu title, DEFINE BAR creates a menu item.

Straight from the VFP Help File:
DEFINE MENU creates the menu bar, menu titles are created with DEFINE PAD. DEFINE POPUP creates a menu for each menu title. DEFINE BAR creates items on each of the menus. [sig]<p>Jon Hawkins<br><a href=mailto: jonscott8@yahoo.com> jonscott8@yahoo.com</a><br><a href= > </a><br>Focus on the solution....Not the problem.[/sig]
 
I wonder if anyone checks over the sample apps like I do. There is a nice example of shortcut menus there by both hand coding them and using the menu designer to create one. Does anybody use the #PREPOP generative directive? Instead of explaining I'll just paste the sample app help for one of the shortcuts menus here. Kinda long but hope it contributes to the thread.

Display Shortcut Menus
File: ...\Samples\Vfp98\Solution\Menus\Shortcut.scx

This sample illustrates displaying shortcut menus when a user &quot;right-clicks&quot; an object. When you have created a shortcut menu in the Menu Designer, the code in the form to activate the menu is very simple. The following code is associated with the RightClick event of the form:

DO frmshort.mpr WITH THIS

The following code is associated with the RightClick event of the edit boxes on the form:

DO edtshort.mpr WITH THIS

The FRMSHORT Menu
The FRMSHORT menu was designed to take an object parameter. The following code is included in the menu's setup code:

PARAMETER oREF
#PREPOP

The #PREPOP generative directive causes the code in the menu's cleanup to be generated before the ACTIVATE POPUP command. This allows you to disable or enable menu items at run time, as well as display check marks beside menu items.

The code associated with the menu items sets properties of the object that was passed to the .mpr as a parameter. For example, the Always on top item sets the AlwaysOnTop property of the form.

[sig]<p>John Durbin<br><a href=mailto: john@johndurbin.com> john@johndurbin.com</a><br><a href= </a><br>MCP Visual FoxPro<br>
ICQ VFP ActiveList #73897253[/sig]
 
Hello Jon an John,

Thanks for your support problem solved, I've been busy with some other thinks that's why it's a few days later.

After replacing shortcut with smTest the problem was still there. Then I read the info form Johnthe code in the menu's cleanup to be generated before the ACTIVATE POPUP command. This allows you to disable or enable menu items at run time, as well as display check marks beside menu items And I placed my code before ACTIVATE POPUP in .mpr and the problem was gone. finaly... :)

Jon, FWIW, I would move the menu definition into a .prg file. But what to do with the .mpr file, what is the exact reason of it and howto do?

Than there is another question, I come from the DOS envoirement (C++ Pascal) and a little bit of Delphi and VB, so I didn't know so much about VFP. I've bought one book &quot;Programmers Guide&quot; from Ms, but the basic of VFP with good examples are not in the book (for example making a .mpr file with out re-generating) So, what is a good book for me to learn the basic's of VFP (so I won't ask such stuppid questions)?

Thanks, for your support Jon and John!!!!!!!!!!!

Charl


[sig][/sig]
 
I too have had a lot of trouble predicting the behavior of mpr(s). I write all my menu's from scratch in a PRG. I suppose it is because I'm pig headed and never bothered to master the MPR builder. I can write/debug/deploy my menu much faster in a PRG. IMHO MPR is more trouble than it is worth.

John D. Kudos on the #PREPOP I had never heard of it, but will try it out soon. [sig]<p> Pete<br><a href=mailto:blindpete@mail.com>blindpete@mail.com</a><br><a href= > </a><br>What your mother told you is true! You will go blind! (from moonshine anyway)[/sig]
 
Pete, I agree with you completely, but making menu from zero without proer knowledge is quite a mess for beginners. MPR files are just for good start. Generate than look into MPR code to see how it works. Than you can create you own menu using sample from MPR. [sig]<p>Vlad Grynchyshyn<br><a href=mailto:vgryn@softserve.lviv.ua>vgryn@softserve.lviv.ua</a><br><a href= Serve</a><br>The professional level of programmer could be determined by level of stupidity of his/her bugs[/sig]
 
agreed [sig]<p> Pete<br><a href=mailto:blindpete@mail.com>blindpete@mail.com</a><br><a href= > </a><br>What your mother told you is true! You will go blind! (from moonshine anyway)[/sig]
 
So if I understand you could use a .prg file or .mpr, .prg to make it all by yourself, and by .mpr generate and rename all the 'shortcut' to 'mypopupmenu'?

And the best / most beautifull way of doing is by using .prg files and make it all by yourself? Is it the best way?

Charl [sig][/sig]
 
If you use the Menu designer as a shortcut designer you don't need to rename anything. AFA a PRG, the code to create the shortcut menu can reside in a method of your form or subclassed control. Do you have the VFP samples? Did you check out the menu samples? [sig]<p>John Durbin<br><a href=mailto: john@johndurbin.com> john@johndurbin.com</a><br>MCP Visual FoxPro<br>
ICQ VFP ActiveList #73897253[/sig]
 
RedLion, YES. MPR gives you only basic functionality.
In our application we build menu for each user separately using data about which menu items accessable for that user. We have ability to add new menu items into data, for example, to run MS Word from application menu. We control 'Exit' menu item to be accessable even when modal form opened. We have shortcut menus maybe for every little control on the form. Our grids contains merged control and grid shortcut menus without additional programming. I even don't know all features of this because it was not part of my job in our team.
All above could be organized only by manual programming of menu layouts. .MPR menu looks so basic and beginner compare to above...
[sig]<p>Vlad Grynchyshyn<br><a href=mailto:vgryn@softserve.lviv.ua>vgryn@softserve.lviv.ua</a><br><a href= Serve</a><br>The professional level of programmer could be determined by level of stupidity of his/her bugs[/sig]
 
But that's just it Vlad. I think he need a beginner point and go from there. You underestimate your ability. It is very advanced IMO [sig]<p>John Durbin<br><a href=mailto: john@johndurbin.com> john@johndurbin.com</a><br>MCP Visual FoxPro<br>
ICQ VFP ActiveList #73897253[/sig]
 
Thanks for all the information, I'm understanding it a little bit better now.

Do you have the VFP samples? Did you check out the menu samples?

I've looked in the examples, And I saw that there where some variables given to the menu, and that it had init and clean up code, but I didn't know where to look for that code, I 've looked everywhere in the menu-designer (stupid from me!)

Thanks all of you!

Charl
[sig][/sig]
 
When you start up the Samples App have the option to open it and view the form, menus etc or run it. When you run it, if you click the bottom left button of the running form it gives some details and explaination of the sample. [sig]<p>John Durbin<br><a href=mailto: john@johndurbin.com> john@johndurbin.com</a><br>MCP Visual FoxPro<br>
ICQ VFP ActiveList #73897253[/sig]
 
Here is quickie example for you...

Pads are the top layer of menus
define your pads...
activate your pads...
add bars to pads...
set actions to bars...
and thats pretty much it.


SET SYSMENU AUTOMATIC
*Define Menu Pads
DEFINE PAD FILE OF _msysmenu PROMPT &quot;\<File&quot; ;
BEFORE _medit
DEFINE PAD manage OF _msysmenu PROMPT &quot;\<Manage&quot; ;
AFTER _medit ;
SKIP FOR EMPTY(m.open_proj)

*Define PAD actions
ON PAD FILE OF _msysmenu ACTIVATE POPUP FILE
ON PAD manage OF _msysmenu ACTIVATE POPUP manage


*File Menu
DEFINE POPUP FILE MARGIN RELATIVE
DEFINE BAR 1 OF FILE PROMPT &quot;\<New&quot; ;
KEY ctrl+N, &quot;Ctrl+N&quot; ;
SKIP FOR TYPE('mybrowse.tag') <> &quot;U&quot;
DEFINE BAR 2 OF FILE PROMPT &quot;\<Open&quot; ;
KEY ctrl+o, &quot;Ctrl+O&quot; ;

*Manage Menu
DEFINE POPUP manage MARGIN RELATIVE
DEFINE BAR 1 OF manage PROMPT &quot;\<Information&quot;

*File menu actions
ON SELECTION BAR 1 OF FILE DO add_proj.prg
ON SELECTION BAR 2 OF FILE DO open_it.prg

*Manage menu actions
ON SELECTION BAR 1 OF manage DO FORM ManInfo.SCX

Hope this example is useful! [sig]<p> Pete<br><a href=mailto:blindpete@mail.com>blindpete@mail.com</a><br><a href= > </a><br>What your mother told you is true! You will go blind! (from moonshine anyway)[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top