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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing the System Menu with a Custom Menu

Status
Not open for further replies.

neculai

Programmer
Jul 21, 2004
13
CA
When I try to replace the System Menu with a Custom Menu, I have difficulties:
- if I click anywhere outside the Custom Menu, the Menu just disappears and I am stuck in Visual FoxPro9, not being able to close it, so I need to call Task Manager to force closing.
- if I click on an Item, the Form shows and works. When I click on x to Close the Form, it calls Destroy where I have the line code Activate Menu, but the Form is not destroyed and stays on screen.
- When I try to close the Menu clicking on Alt X-Q, it simply doesn't work and I'm not able to close the Menu. For this, I tried to call a small Form where in Init I have the line code Close Events. I've also tried _SCREEN.Release, no success.

I post below some code for better understanding of what I'm trying to accomplish.

main.prg

With _Screen
.BackColor = rgb(0,128,64)
.Caption = 'App Manager 20'+ Substr(Dtoc(Date()),7,2)
.Height = 780
.Width = 1020
Endwith

Define Pad padOne Of CustomMnu Prompt '\<Countries' Key Alt+C, ''
Define Pad padTwo Of CustomMnu Prompt 'E\<xit' Key Alt+X, ''

On Pad padOne Of CustomMnu Activate Popup popCountries
On Pad padTwo Of CustomMnu Activate Popup popExit

Define Popup popCountries Margin Message 'Countries'
Define Bar 1 Of popCountries Prompt '\<Germany'
Define Bar 2 Of popCountries Prompt '\<France'
Define Bar 3 Of popCountries Prompt '\<Italy'

Define Popup popExit Margin Message 'Exit'
Define Bar 1 Of popExit Prompt '\<Quit'

On Selection Bar 1 Of popCountries Do Form Germany Name Germany
On Selection Bar 2 Of popCountries Do Form France Name France
On Selection Bar 3 Of popCountries Do Form Italy Name Italy

On Selection Bar 1 Of popExit _Screen.Release

Activate Menu CustomMnu

Read Events

Deactivate Menu CustomMnu
Release Menu CustomMnu Extended

Close Databases All

Messagebox(' Normal exit! ', 0+64+0, 'Administrator')

Clear All
Quit

Thank you very much for any help! :)

Neculai
 
Why don't you use the menu designer?

Also take a look at SET SYSMENU

One more thing: As you don'T define an Edit menu, simple and essential things like Copy & Paste with CTRL+C, CTRL+V don't work anymore, when your menu is active.

I suggest you go into the project manager in the Other tab, choose Menus, click New, then Menu and pick "Quick Menu" from the Menu menu, then you have all essentials, you may remove some pads and items.
You can use Preview and the menu will replace the sysmenu and you can see how it looks. In the middle of the screen a small window appear, keep that running. Picking a menu item in this mode will not cause the command or procedure you defined to run, but you'll see the window in the middle echoes what you selected and show what would be done. If you click OK there the preview mode is exited.

You're still in the menu designer. When the preview showed what you wanted to get, select Generate... from the Menu menu and a mpr will be generated. This'll then show you how you build this menu by code. You may take it from there much easier than doing it from scratch like you did.

One thing: _Screen.Release() is not the way to close VFP. As you do READ EVENTS, the quit menu item should do CLEAR EVENTS, not _Screen.Release(). Only then your code after READ EVENTS will run. There you should have SET SYSMENU TO DEFAULT to restore the sysmenu.

Bye, Olaf.
 
Hi Neculai, and welcome to the forum.

There are several things wrong with your menu.

First, you are trying to define a pad of Custommnu, but you have not defined Custommneu. You might find it easier to do it like this:

Code:
SET SYSMENU TO
SET SYSMENU AUTOMATIC

DEFINE PAD PadOne OF _MSYSMENU PROMPT "\<Countries" KEY ALT+C, ""
DEFINE PAD PadTwoOF _MSYSMENU PROMPT "\<Exit" KEY ALT+X, ""
ON PAD PadOne OF _MSYSMENU ACTIVATE POPUP Countries
ON PAD PadTwo OF _MSYSMENU ACTIVATE POPUP Exit

Then go ahead with the your DEFINE POPUP, DEFINE BAR and ON SELECTION BAR comands. You don't need ACTIVATE MENU.

Next, in the Exit command, you cannot simply QUIT. You need CLEAR EVENTS to take you past your READ EVENTS. After READ EVENTS, you should close any open forms, and then QUIT. If you are in the development environment, you should also SET SYSMENU TO DEFAULT to restore the default menu. You don't need DEACTIVATE MENU or RELEASE MENU.

You should not put ACTIVATE MENU in the form's Destroy event.

I suggest you try the above first, and if it is still not working, we can take it from there.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks, Olaf and Mike. Following your advice, I've fixed my menu, and now it works great, I've used Mike's approach. I would have liked to use different fonts and sizes for the menu characters, but it seems it's not recommendable because these are Windows settings. Tried
DEFINE PAD PadOne OF _MSYSMENU PROMPT "\<Countries" KEY ALT+C, "" FONT 'Arial', 30
but nothing happens.

For closing the menu and exiting Visual FoxPro, I run a small.prg file with a single line of code Clear Events.
On Selection Bar 1 Of popExit Do small
so the control is given to the code after Read events, where I do all the clean up.
Read Events
Clear All
Close Databases All
Set Resource Off
Erase FOXUSER.*
Messagebox(' Normal exit! ', 0+64+0, ' Administrator ')
Quit

I would also have liked to be able to close the application from the upper right corner clicking on [X], but it says Cannot quit Visual Foxpro, so, the only way to exit the app is through the menu.

All the best,
Neculai :)
 
>be able to close the application from the upper right corner clicking on [X],
You have to define ON SHUTDOWN for that. eg ON SHUTDOWN CLEAR ALL, better yet ON SHUTDOWN QUIT.

I see you do SET RESOURCE OFF it to be able to ERASE FOXUSER.*. If you don't want it, include a ascii file named config.fpw and with RESOURCE=OFF and it's not even created in the first place.
Close All and Close Databases all is also done automatically.

there is not much need for any clean up code after READ EVENTS, no matter if you exit by QUIT or by CLEAR EVENTS, as the shutdown of the VFP runtime does close all databases, tables, filehandles, datasessions, transactions, etc. and cleans up overall anyway.

If you do ON SHUTDOWN QUIT, the QUIT causes the destroy of all objects and cleanup code should be in them in their destroy event, and in their unload and queryunload (for forms) events. So there is enough room to clean up, QUIT is no dirty and forced exit.

Bye, Olaf.
 
Glad to hear you've got it working, Neculai.

Regarding the font and font size, the FONT clause has no effect with DEFINE PAD if you are using _MSYSMENU (which you are), You will need to add the clause to the individual DEFINE BAR commands.

I'm not sure why you want to do SET RESOURCE OFF and ERASE FOXUSER.*. If you are not using the resource files, then these commands have no effect. If you don't want FOXUSER.* to persist, better to do as Olaf advised, that is, put RESOURCE = OFF in your Config.FPW file.

Finally, I question your MESSAGEBOX() just before the QUIT. There's nothing wrong with this from the programming point of view, but do you really need to tell your users that you are existing the program?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top