Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. articles. downloads. faq. members. files. rss.
 From: Stefan Wuebbe
  Where is Stefan Wuebbe?
 Hamburg
 Germany
 Stefan Wuebbe
 To: Foxy Hound
  Where is Foxy Hound?
 DAVAO
 Philippines
 Foxy Hound
Subject: RE: Modifying Menus on Runtime
Thread ID: 467883 Message ID: 467900 # Views: 61 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Menus
Date: Saturday, August 24, 2019 9:11:49 AM         
   



> >
> >
> > Check DEFINE PAD in HELP.
> >
> >
> > -----------------
> > Borislav Borissov
> >
> > Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
> > The only thing normal about database guys is their tables.
>
>
> Hi Borislav Borissov !
>
> thanks ! but i already did this and as i stated in my original post i was able to insert a NEW PAD in the MENU
> my problem was that i cant insert a NEW BAR in a target PAD. maybe because the MENU is already created ?
>
> i was able to DO MENU.MPR with thisform, "MY_PREFERRED_MENU_NAME" so that AFTER the menu is created i can reference it using its name MY_PREFERRED_MENU_NAME
>
> NOW lets say i wanted to add a new BAR called "ADJUSTMENTS" under PAD "TRANSACTIONS"
>
> TRANSACTION_PAD = GETPAD("MY_PREFERRED_MENU_NAME", 2 ) && it appears to be a SYS(2015) name generated by GENMENU
>
> CAN I do ?
> DEFINE BAR (SOMEBARNUMBER) OF (TRANSACTION_PAD) PROMPT "ADJUSTMENTS"
>
> It gives me an error that the menu is not defined in define menu etc.


If you want to use the Menu Designer, you can define Pad Names and Bar Numbers there.
Alternatively, you can create, i.e. DEFINE Menus, Pads, Bars etc anytime directly in your code.
The Menu name itself would depend on your goal, e.g. whether you want to use the _Screen Menu, _MSYSMENU,
as opposed to a so called "SDI" menu belonging to a certain Form window,
or a right-click Shortcut / Context menu.

When you run the following sample, you'd get a dynamic right-click context menu of a TestForm where the content would get dynamically changed depending on a hypothetical "User Privileges" concept



hth
-Stefan




#define _USER_PRIVILEGE_LEVEL_GUEST		1
#define _USER_PRIVILEGE_LEVEL_OPERATOR	3
#define _USER_PRIVILEGE_LEVEL_ADMIN		5


LOCAL oForm as Form
oForm = CREATEOBJECT('TestForm')
oForm.Show(1)
RETURN

DEFINE CLASS TestForm as Form
	AutoCenter = .T.
	nUserLevelCurrent = _USER_PRIVILEGE_LEVEL_OPERATOR

	PROCEDURE RightClick
		Thisform.ShortcutMenu()
	ENDPROC

	PROCEDURE ShortcutMenu
		DEFINE POPUP sc SHORTCUT RELATIVE FROM MROW(),MCOL()

		DEFINE BAR 1 OF sc PROMPT "Operator's Bar"
		ON SELECTION BAR 1 OF sc MESSAGEBOX("Operator's Bar")
		SET SKIP OF BAR 1 OF sc (_screen.ActiveForm.nUserLevelCurrent < _USER_PRIVILEGE_LEVEL_OPERATOR)

		DEFINE BAR 2 OF sc PROMPT "Admin Bar"
		ON SELECTION BAR 2 OF sc MESSAGEBOX("Admin's Bar")
		SET SKIP OF BAR 2 OF sc (_screen.ActiveForm.nUserLevelCurrent < _USER_PRIVILEGE_LEVEL_ADMIN)

		DO CASE
			CASE Thisform.nUserLevelCurrent = _USER_PRIVILEGE_LEVEL_ADMIN
				DEFINE BAR 3 OF sc PROMPT "Admin's optional Bar"
				ON SELECTION BAR 3 OF sc MESSAGEBOX("Admin's optional Bar")
			CASE Thisform.nUserLevelCurrent = _USER_PRIVILEGE_LEVEL_OPERATOR
				DEFINE BAR 4 OF sc PROMPT "Operator's optional Bar"
				ON SELECTION BAR 4 OF sc MESSAGEBOX("Operator's optional Bar")
		ENDCASE


		ACTIVATE POPUP sc
	ENDPROC

	PROCEDURE GetUserPrivileges()
		* In a "real" context, this method might ask something
		* like a "global application object" m.goApp
		RETURN Thisform.nUserLevelCurrent
	ENDPROC

	ADD OBJECT cboPrivilegeLevel as PrivilegeCombo WITH ;
		Left = 100, Top = 100, ControlSource = 'Thisform.nUserLevelCurrent'

ENDDEFINE

DEFINE CLASS PrivilegeCombo as ComboBox
	BoundColumn = 2
	BoundTo = .T.
	PROCEDURE Init
		LOCAL lcLevel

		This.AddItem('')

		This.AddItem('Guest')
		lcLevel = TRANSFORM(_USER_PRIVILEGE_LEVEL_GUEST)
		This.AddListItem(m.lcLevel,This.NewItemID,2)

		This.AddItem('Operator')
		lcLevel = TRANSFORM(_USER_PRIVILEGE_LEVEL_OPERATOR)
		This.AddListItem(m.lcLevel,This.NewItemID,2)

		This.AddItem('Admin')
		lcLevel = TRANSFORM(_USER_PRIVILEGE_LEVEL_ADMIN)
		This.AddListItem(m.lcLevel,This.NewItemID,2)
	ENDPROC
ENDDEFINE


ENTIRE THREAD

Modifying Menus on Runtime Posted by Foxy Hound @ 8/23/2019 5:48:48 AM
RE: Modifying Menus on Runtime Posted by Borislav Borissov @ 8/23/2019 8:44:19 AM
RE: Modifying Menus on Runtime Posted by Foxy Hound @ 8/24/2019 6:27:02 AM
RE: Modifying Menus on Runtime Posted by Stefan Wuebbe @ 8/24/2019 9:11:49 AM
RE: Modifying Menus on Runtime Posted by Foxy Hound @ 8/25/2019 2:25:37 AM
RE: Modifying Menus on Runtime Posted by Stefan Wuebbe @ 8/25/2019 10:43:08 AM
RE: Modifying Menus on Runtime Posted by Foxy Hound @ 8/25/2019 10:56:09 AM
RE: Modifying Menus on Runtime Posted by Doug Hennig @ 8/23/2019 4:44:56 PM
RE: Modifying Menus on Runtime Posted by Yuri Rubinov @ 8/23/2019 11:40:02 PM
RE: Modifying Menus on Runtime Posted by Chuanbing Chen @ 8/26/2019 1:57:55 AM