Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to Add/Remove Menu Items Programmatically
Message
De
20/06/2005 10:52:19
 
 
À
20/06/2005 01:08:03
Raoshan Kumar
Softinfo Systems Pvt. Ltd.
New Delhi, Inde
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire de menu & Menus
Versions des environnements
Visual FoxPro:
VFP 7 SP1
OS:
Windows 2000 SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01024752
Message ID:
01024858
Vues:
19
>Hi All
>
>How it can be possible to Add/Remove Some menu Items (like PAD, BAR etc.) programatically (while application is running);
>
>Again Is there any way to renumber the Prompts of a menu popup.
>
>Also Is there any provision to hide a Bar from the menu popup or Hide a Pad from the Menu bar.
>
>Thanks
>
>Raoshan

Below instruction is about REMOVING only. The idea is that you put ALL menu items in the original menu and that inappropriate items are removed upon creation of the menu. In my example it uses a routine called UserAccess() which decides whether or not it must actually be removed. Of course, you're supposed to write your own 'useraccess' like function.

Open your test menu, e.g. testmenu.mnx.
Give each menu item a pad name (see Options of the menu item) if it says Pad Name, e.g. 'main_file', 'main_edit'.
Give each menu item a barnumber (see Options of the menu item) if it says Bar#. Use 100's (e.g. 101, 102, 103) for items in the first menu pad. Use 200's (e.g. 201, 202) for items in the second menu pad. And so on.

Choose View in the menu's menu, then General Options, then Cleanup. Put there code like herunder:
*	Conditionally release bars.

ReleaseBar( 101, a_menupops[1], 'mfn' )
ReleaseBar( 102, a_menupops[1], 'mfo' )
ReleaseBar( 103, a_menupops[1], 'mfs' )
* etc.
ReleaseSeparators( a_menupops[1], 'main_file', m.cMenuName )

ReleaseBar( 201, a_menupops[2], 'men' )
ReleaseBar( 202, a_menupops[2], 'mnu' )
* etc.
ReleaseSeparators( a_menupops[2], 'main_edit', m.cMenuName )
releasebar.prg:
*	Conditionally releases a bar.

* Parameters:
*	1	tnBar		Barnumber.
*	2	tcPopup		Popup name.
*	3	tcUA		UserAccess string.
lparameter tnBar, tcPopup, tcUA

if not UserAccess( tcUA )
	release bar tnBar of (tcPopup)
endif
releaseseparators.prg:
*	Releases separators that are senseless.
*	Even releases the whole pad if it contains no longer any item.

* Parameters:
*	1	tcPopup		Popup name.
*	2	tcPad		Pad name.
*	3	tcMenu		Menu name.

lparameters tcPopup, tcPad, tcMenu
local llPrevSep, ln, lnBar

llPrevSep = .f.

for ln = cntbar( m.tcPopup ) to 1 step -1
	*
	lnBar = getbar( m.tcPopup, m.ln )
	*
	if empty( prmbar( m.tcPopup, m.lnBar ) )	&& a separator has an empty prompt
		*
		if m.ln = 1 or m.ln = cntbar( m.tcPopup ) or m.llPrevSep = .t.
			*
			release bar m.lnBar of ( m.tcPopup )
		else
			llPrevSep = .t.
		endif
	else
		llPrevSep = .f.
	endif
next

if cntbar( m.tcPopup ) > 0
	*
	lnBar = getbar( m.tcPopup, 1 )
	*
	if empty( prmbar( m.tcPopup, m.lnBar ) )	&& if first bar is a separator
		*
		release bar m.lnBar of ( m.tcPopup )
	endif
endif

if cntbar( m.tcPopup ) = 0				&& if there's no longer any bar
	*
	release pad ( m.tcPad ) OF ( m.tcMenu )		&& then remove the pad too
endif
Groet,
Peter de Valença

Constructive frustration is the breeding ground of genius.
If there’s no willingness to moderate for the sake of good debate, then I have no willingness to debate at all.
Let's develop superb standards that will end the holy wars.
"There are three types of people: Alphas and Betas", said the beta decisively.
If you find this message rude or offensive or stupid, please take a step away from the keyboard and try to think calmly about an eventual a possible alternative explanation of my message.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform