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!

Custom menu problems

Status
Not open for further replies.

Rajesh Karunakaran

Programmer
Sep 29, 2016
549
MU
Hi Friends,

I am trying to implement a custom menu in my program. Main reason for not using _msysmenu is that the main menu bar and its pads do not support fonts, font size, style etc even though the subsequent bars of pads and popup have font specifications.

Below is my code I am trying. The problem is it displays the menu but the moment I click anywhere outside the menu, the menu disappears and I am stuck up and foxpro wouldn't allow me to do anything.

Code:
_menuFontFace  = 'Arial'
_menuFontSize  = 9
_menuStyleChar = 'B'

SET SYSMENU TO  

DEFINE MENU _mainmenu IN SCREEN FONT _menuFontFace,_menuFontSize STYLE _menuStyleChar COLOR SCHEME 3 NOMARGIN

DEFINE PAD padMasters   OF _mainmenu PROMPT "Masters    "     FONT _menuFontFace,_menuFontSize STYLE _menuStyleChar COLOR SCHEME 1
DEFINE PAD padExit      OF _mainmenu PROMPT "Exit       "      FONT _menuFontFace,_menuFontSize STYLE _menuStyleChar COLOR SCHEME 1

ON SELECTION PAD padMasters OF _mainmenu ACTIVATE POPUP popMasters
ON SELECTION PAD padExit    OF _mainmenu do QuitMenu

*/ Masters
DEFINE POPUP popMasters
    DEFINE BAR 01 OF popMasters PROMPT "  Masters First" FONT _menuFontFace,_menuFontSize STYLE _menuStyleChar
    DEFINE BAR 02 OF popMasters PROMPT "\-"	SKIP
    DEFINE BAR 03 OF popMasters PROMPT "  Masters Third" FONT _menuFontFace,_menuFontSize STYLE _menuStyleChar

    ON SELECTION BAR 01 OF popMasters do FORM frmMasters1	&& WITH 'SAVE', ,.T. TO lRcvdValue
    ON SELECTION BAR 03 OF popMasters do FORM frmMasters3	&& WITH 'SAVE', ,.T. TO lRcvdValue
    
ACTIVATE MENU _mainmenu 
READ EVENTS
	
*****************************	
PROCEDURE QuitMenu	
*****************************	
	CLEAR EVENTS 
	DEACTIVATE MENU _mainmenu 
	RELEASE MENUS _mainmenu EXTENDED 
	SET SYSMENU TO DEFAULT

By the way, I came across the below topic but it discusses about the _MSYSMENU which I do not want to use because of FONT issues.
That is why I created this new thread. Hope that makes sense.

What is I am missing? Can anyone help?

Thanks
Raj
 
the moment I click anywhere outside the menu, the menu disappears

That is completely normal. It is the standard Windows behaviour. It is not something you would normally want to override.

If you want to give your users a list of options, with the options remaining visible while the user clicks elsewhere, then you don't want this type of menu. Consider instead using a listbox. A listbox can contain the same options as a menu, and you cam make it react to user choices in a similar way. And by setting its RowSourceType to 9, you can provide the support for different fonts that you asked for.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,

I think I have not explained it well!

I want a menu system just like the Foxpro standard menu. This menu will be my main application menu and contain basically options for all modules of the application (similar to any business application). In the code I pasted in my query above, I added only a few items because it's just for testing. This menu will appear immediately after the user logs in and it should stay there until and unless user selects to exit application by clicking on the 'Exit' option in menu. As in general cases, if the user selects an option usually a form will appear for that module and then the menu will be disabled to select any item from it until the user exists from that module (the form). But now, when I run the code above, the menu appears but when I click outside, it vanishes. As you know it, the standard menu is not like that.

I don't want to use the foxpro _MSYSMENU because I want to set the FONT even for the main top bar pads items of the menu. The foxpro menu doesn't allow this.

Does this make sense? Is there any way out?

Thank you for your time,
Rajesh
 
Rajesh,

OK, that makes sense. I understood you were saying that the individaul pads were disappearing. But you are saying that the entire menu disappears. I agree that's not what you want.

However, there is nothing stopping you from using fonts with a menu based on _MSYSMENU. What I suggest you do is to use the menu designer to generate your menu. Then open the generated MPR file in a text editor, and manually add the FONT clauses to your DEFINE PAD and DEFINE BAR commands. I think that will do what you want.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,

I tried that but failed to see the effect. In fact, if I code it manually or use menu builder, the top most menu pads do not support font changes in case of _msysmenu. Everything below that is okay for font changes.

Eg: Menu created by foxpro
Code:
SET SYSMENU TO
SET SYSMENU AUTOMATIC

DEFINE PAD _5c518ojhd OF _MSYSMENU PROMPT "Masters" COLOR SCHEME 3 ;
	KEY ALT+M, ""
DEFINE PAD _5c518ojhe OF _MSYSMENU PROMPT "Utilities" COLOR SCHEME 3 ;
	KEY ALT+U, ""
DEFINE PAD _5c518ojhf OF _MSYSMENU PROMPT "Exit" COLOR SCHEME 3 ;
	KEY ALT+E, ""
ON PAD _5c518ojhd OF _MSYSMENU ACTIVATE POPUP masters
ON PAD _5c518ojhe OF _MSYSMENU ACTIVATE POPUP utilities
ON SELECTION PAD _5c518ojhf OF _MSYSMENU ;
	DO _5c518ojhg ;
	IN LOCFILE("APP\PRGS\CUSTMENU" ,"MPX;MPR|FXP;PRG" ,"WHERE is CUSTMENU?")

DEFINE POPUP masters MARGIN RELATIVE SHADOW COLOR SCHEME 4
DEFINE BAR 1 OF masters PROMPT "Master first"
DEFINE BAR 2 OF masters PROMPT "Masters second"

DEFINE POPUP utilities MARGIN RELATIVE SHADOW COLOR SCHEME 4
DEFINE BAR 1 OF utilities PROMPT "Scrip Import"
DEFINE BAR 2 OF utilities PROMPT "Group Assignment"

Now, I tried to change font of 'Masters', 'Utilities' PADs (the first DEFINE PAD which is the topmost items in the menu hierarchy) in the MPR file as below
Code:
SET SYSMENU TO
SET SYSMENU AUTOMATIC

DEFINE PAD _5c518ojhd OF _MSYSMENU PROMPT "Masters" COLOR SCHEME 3 ;
	KEY ALT+M, "" FONT "Arial", 11
DEFINE PAD _5c518ojhe OF _MSYSMENU PROMPT "Utilities" COLOR SCHEME 3 ;
	KEY ALT+U, "" FONT "Arial", 11
DEFINE PAD _5c518ojhf OF _MSYSMENU PROMPT "Exit" COLOR SCHEME 3 ;
	KEY ALT+E, "" FONT "Arial", 11
ON PAD _5c518ojhd OF _MSYSMENU ACTIVATE POPUP masters
ON PAD _5c518ojhe OF _MSYSMENU ACTIVATE POPUP utilities
ON SELECTION PAD _5c518ojhf OF _MSYSMENU ;
	DO _5c518ojhg ;
	IN LOCFILE("APP\PRGS\CUSTMENU" ,"MPX;MPR|FXP;PRG" ,"WHERE is CUSTMENU?")

DEFINE POPUP masters MARGIN RELATIVE SHADOW COLOR SCHEME 4
DEFINE BAR 1 OF masters PROMPT "Master first" FONT "Arial", 11
DEFINE BAR 2 OF masters PROMPT "Masters second" FONT "Arial", 11

DEFINE POPUP utilities MARGIN RELATIVE SHADOW COLOR SCHEME 4
DEFINE BAR 1 OF utilities PROMPT "Scrip Import" FONT "Arial", 11
DEFINE BAR 2 OF utilities PROMPT "Group Assignment" FONT "Arial", 11

But it doesn't make any changes. However, the font of BARs of POPUPs are okay.
This is what I am trying to explain. The topmost items of the menu, the PADs in place of File, Edit, View, Format etc do not support font changes but everything after that are okay.

Thanks for your time,
Rajesh

 
I've just run your code and can confirm what you are seeing. You were right that the FONT clause does work with the system menu. To quote from HackFox:

HackFox said:
These clauses {FONT and STYLE] let you decide what font to use when you're not working with the system menu. The system menu picks up its font settings from the Registry and ignores any fonts you specify.

(My emphasis.)

So you will need to revert to your _mainmenu after all. However, the syntax that you are now using should be correct. Try something like this:

Code:
DEFINE MENU _mainmenu 

DEFINE PAD _5c518ojhd OF _mainmenu PROMPT "Masters" COLOR SCHEME 3 ;
	KEY ALT+M, "" FONT "Arial", 11
DEFINE PAD _5c518ojhe OF _mainmenu PROMPT "Utilities" COLOR SCHEME 3 ;
	KEY ALT+U, "" FONT "Arial", 11
DEFINE PAD _5c518ojhf OF _mainmenu PROMPT "Exit" COLOR SCHEME 3 ;
	KEY ALT+E, "" FONT "Arial", 11
ON PAD _5c518ojhd OF _mainmenu ACTIVATE POPUP masters
ON PAD _5c518ojhe OF _mainmenu ACTIVATE POPUP utilities
ON SELECTION PAD _5c518ojhf OF _mainmenu ;
	DO _5c518ojhg ;
	IN LOCFILE("APP\PRGS\CUSTMENU" ,"MPX;MPR|FXP;PRG" ,"WHERE is CUSTMENU?")

DEFINE POPUP masters MARGIN RELATIVE SHADOW COLOR SCHEME 4
DEFINE BAR 1 OF masters PROMPT "Master first" FONT "Arial", 11
DEFINE BAR 2 OF masters PROMPT "Masters second" FONT "Arial", 11

DEFINE POPUP utilities MARGIN RELATIVE SHADOW COLOR SCHEME 4
DEFINE BAR 1 OF utilities PROMPT "Scrip Import" FONT "Arial", 11
DEFINE BAR 2 OF utilities PROMPT "Group Assignment" FONT "Arial", 11 

ACTIVATE MENU _mainmenu

Notice that I have added an ACTIVATE MENU. I don't think you need a FONT clause in the DEFINE MENU because it should pick up the fonts from the individual pads, but you can always experiment.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,

But if I use a custom menu, the other problem comes up. When you activate, the menu appears and I can select an item to run its code, a form or a prg. But the moment I click somewhere on screen area, the menu vanishes and then I stuck up. It doesn't behave the way the system menu behaves. I had added a 'READ EVENTS' after ACTIVATE MENU and not sure if that was the problem. Anyway, will try different ways and get back here. Meanwhile, if you get any solution, please let me know.

Rajesh
 
I'd recommend quite the opposite of what you did. Don't have menu cleanup code, the menu should stay. Keep a READ EVENTS in your main.prg and not within any manu code, neither setup nor cleanup code.
Activate the menu with ACTIVATE MENU (m.cMenuName) NOWAIT in your main.prg and have READ EVENTS afterwards.

If your menu then vanishes you have cleanup code in the menu designer, which releases the menu, that's not what you do.

Also look into the way genmenu generates a menu prg (mpr file extension) when you choose the menu code to be generated for a top level form. While you edit the menu in the menu go for View->General Options:

menu_general_yxbvnk.jpg


Bye, Olaf.



Olaf Doschke Software Engineering
 
Why do you want to override the user's choices for menu fonts?

Tamar
 
Hi Olaf,
I think what you say make sense. I will check and let all of us know.

Hi TamarGranor,
Not sure what you really meant by "user's choices for menu fonts"!
In fact, the user doesn't want that conventional small fonts (usually verdana I think) as in foxpro standard menu (the _MSYSMENU). They want it to be another font and a bit bigger because their forms use that particular font and size for labels text boxes etc as a standard and want the same font to be throughout the menu system also. Too, they don't want any feature to play with the fonts by their users. The font stay standard throughout their software.

Thank you all,
Rajesh


 
>The font stay standard throughout their software.

Well, what Tamar surely thinks of as "what the users want", is what is configured in Windows. Users can change system fonts, unless group policies hinder them.
It's obviously not giving you full control, though, Windows settings are about the menu and form captions and some more, like text/buttons of Messageboxes, the interior of forms is up to the developer.

But indeed you could turn it around, make use of system fonts and adapt your inner form look to that, too. Then the overall same look can be accomplished by system settings.

The only downside of this is all other applications would need to go the same route, and they usually don't in terms of interior fonts used in forms. Of course, I don't speak of what Fonts are used in notepad or Word Docs or Excel sheets, that's up to you anyway.

The other issue is that you have too many bad side effects of setting the general icon/font scale factor to something different from 100%.

Windows is a bit of a mess about these font-related things, also because no application developer makes the first step of trying to really write a windows-conform application UI/UX. In VFP you're quite strikingly hindered by the scale factor side effects and thus excused for rolling your own menu. But as long as the scale factor is kept at 100% you could adjust to Windows settings. It's easy to let VFP environment reflect system settings in many aspects vie having SET SYSFORMATS ON in your main.prg startup.

I don't know how you tackle this now if the CI of the company is the determining factor or your application offers font settings for itself. But it's one of the topics making Windows a design failure. I just need to think about the software typically coming with any graphics card accompanying the Windows dialogs for "Screen Resolution" and "Personalize". Be it the Intel Graphics, Acer Display Management or others. They all come with a very outlandish but vendor specific look not even staying in the norm of normal desktop Windows. Well, and Windows itself is also not nicely contributing to a general look by forcing the full screen completely borderless screens without a titlebar. I guess if you search tek-tips you find a similar rant from me as Windows 8 introduced this new look that still only is a norm for parts of Windows. It's no wonder more esthetically oriented people turn to Apple.

All-in-all, I don't blame you for fulfilling your customers wishes, I just wished less customers would want their CI designs in applications and what's missing in VFP to me more than Unicode or >2GB DBFs is a way to handle themes and scale factor better. The most often question for legacy software is how to turn this off and I can't blame people to be lazy to not go the other route and adapting their applications to themed looks, if that differs to much from OS to OS version and has no consistency from Microsoft anyway. And now, 10 years after Vista haad it'S Aero, Win7 tuned it back a bit and Win8/10 introduced flatland, we have even less consistency. POS systems still use XP, but also typically have their completely own look in fullscreen modes anyway.

There is no such thing as a Microsoft Windows Look, that would make people choose Windows over Apple for design reasons.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Hi Olaf,

Thank you for your elaborated views!

I was not talking about changing the font scaling factor of windows! I would not be bothered about what the user changes on fonts in their general windows setup or any other application. The changes I want are only for the business application I develop.

What I mean to achieve is that, for example, I want (or rather my client) my software entire menu system to use Arial font of size 10 in its top PADs, popups under each PAD and the BARs of popups for each PAD) etc. If I use the foxpro menu system _MSYSMENU, this is not achievable simply because _MSYSMENU doesn't allow us to change its fonts for the topmost PADs. But it allows us to change fonts for all PAD popups and their BARs. This is why I want to use a custom menu.

Now, if I use custom menu, I can change font everywhere in the menu. But, I have problem of menu getting vanished if I click somewhere on screen. For that, I will certainly try the ways you explained in your earlier reply and let you all know.

Thank you so much,
Rajesh
 
Rajesh,

Maybe I am missing something. But in your case, forget about _sysmenu and built your own mainmenu which you have to bind to your mainform which has ShowWindow = 2 property.
In your mainmenu you can virtualy set any font and or fontsize. Check the Define Pad in the help. :

DEFINE PAD MenuTitle1 OF MenuBarName PROMPT cMenuTitleText
[AT nRow, nColumn] [BEFORE MenuName2 | AFTER MenuName3]
[NEGOTIATE cContainerPosition [, cObjectPosition]]
[FONT cFontName [, nFontSize [, nFontCharSet]]] [STYLE cFontStyle]
[KEY KeyLabel [, cKeyText]] [MARK cMarkCharacter]
[SKIP [FOR lExpression]] [MESSAGE cMessageText]
[COLOR=SCHEME nSchemeNumber | COLOR ColorPairList]

By the way Arial is, in my opinion, the font which is used by _sysmenu and also this font is, I agree, way out-of-date, there are more modern fonts available like Segui UI.

Koen
 
Hi Koen,

Thank you.

In a custom menu, I am able to change the fonts, no problem in that. But, I am not able to get the custom menu work the way it is supposed to be. The menu appears and I can select options. But when I click somewhere on screen, menu vanishes and then I cannot even quit from VFP. I am not able to figure out where is the problem and what is I am missing.

Will sit with that and if I succeed will post here.

By the way, if possible, a complete working sample of a very simple custom menu (with 1-2 main PADs and 1-2 option BARs in it would be highly appreciated. Fonts are ornaments and not an issue.

Thanks
Rajesh
 
Genmenu generates this, when you pick the top level form option:

DEFINE MENU (m.cMenuName) IN (m.oFormRef.Name) BAR

And oFormRef is a reference of a top-level form you have to pass in.

BAR is the option making it a menu bar that stays.

I once recommended you do a menu with all the commands for it on your own, but indeed once you learn the details about the menu designer it's easier to create a stadard application menu. I think alone of the option to generate a quick menu, adding all the default menus and items.

The other alternative may be using the OOP menu from VFPX:
Bye, Olaf.

Olaf Doschke Software Engineering
 
Arial is, in my opinion, the font which is used by _sysmenu and also this font is, I agree, way out-of-date,

Koen,

Just out or curiosity, in what way is Arial "way out-of-date"? I'm not necessarily disagreeing with you. I'm just wondering what your reason is for considering Arial out of date.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Olaf,

Thank you. Yes, you had suggested as to what to be placed in my main.prg and in the menu code but I am yet to check those things.
Basically, I think, if I place the menu in a top level form (instead of just SCREEN and my problem will be solved. Will check that.
Also, thanks for that OOPMenu url, I may not be using it for time being though.

Thank you so much,
Rajesh
 
Well, if you look at the project description of OOP menu it could be a quick build, as long as you used the menu designer to create an MNX, there is a specific genmenux creating a menu using oop menu classes.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Mike,
The use of fonts is also a fashion, a taste. I remember Arial used to be, together with Times Roman the 2 fonts everybody and als MSOffice used. Since then we have seen Trebuchet others and lately Segoei UI. That's why I call Arial way out-of-date, old fashioned.

----
Rajesh,
sorry I dont understand, in which way a custom menu has different behaviour to the default menu in th VFP menu? If you encounter "The menu appears and I can select options. But when I click somewhere on screen, menu vanishes and then I cannot even quit from VFP. I am not able to figure out where is the problem and what is I am missing." Then your menu is not correctly instantiated. Can you show how you did it?

Koen
 
As Olaf inferred, I meant that users can set the font for menus in Windows settings. Since people with disabilities may use those settings to ensure things work right for them, using your own custom menus may interfere with the ability of people with disabilities to use your application.

I can see two different groups who might be affected. First, people with limited vision may set everyone big so they can see it. In addition, people with movement disabilities may make things big so that they can actually successful use a pointer to choose items.

I don't know what country you're in, but there may be laws requiring software to be accessible to those with disabilities.

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top