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

Navigating Forms Via a Menu

Status
Not open for further replies.

mcoupal

Technical User
Jul 9, 2001
61
0
0
US
(VFP 8.0) I use menus (via the DO Main.MPR method called within my main.prg) in a program and would like a menu item listing all the open forms. Some forms can open more than once (multiple instances/copies). Is there a good way to accomplish this? I assume you could use the system menu (_MWindow) but I'm not sure how along with my existing menus. I have looked at manually adding and deleting menu items (Define Bar and Release Bar) from a pre-existing menu pad, but this is a little daunting. I've done a search and looked in the FAQ. Any suggestions?
 
mcoupal,

Let's say you have a menu and one of the menu bars on that menu is "Window". And, there are 7 sub items on that menu window...

Cascade
Arrange All
____________ (delimiter is one of the items)
Hide
Hide All
Show All
Cycle

...then in each of your forms you would need a few of methods. AddToMenuWindow, SetWindowMark, and DeleteFromMenuWindow. The AddToMenuWindow would be called in the form's Init. SetWindowMark would be called in the form's activate. And DeleteFromMenuWindow would be called in the form's Unload. Also, you will need a procedure, let's call it FormSelect in your procedure file. So here's the code I wrote, it should give you what you want.

Code:
************************************
*!* AddToMenuWindow
LOCAL nBarNumber

nBarNumber = CNTBAR("Window") + 1
IF nBarNumber < 9
	DEFINE BAR 8 OF Window PROMPT "\-"
	nBarNumber = 9
ENDIF

DEFINE BAR nBarNumber OF Window PROMPT TRANSFORM(nBarNumber-8) + " " + thisform.caption
ON SELECTION BAR nBarNumber OF Window DO FormSelect with PROMPT()

************************************
*!* SetWindowMark
Local nBarCounter
FOR nBarCounter = 9 TO CNTBAR("Window")
	sPrompt = PRMBAR("Window", nBarCounter)
	SET MARK OF BAR nBarCounter OF Window TO SUBSTR(sPrompt,AT(" ",sPrompt)+ 1) == thisform.caption
ENDFOR

************************************
*!* DeleteFromMenuWindow
LOCAL nBarCounter, nStopCount, sPrompt, nRemoveBar

nStopCount = CNTBAR("Window")
nRemoveBar = 0
FOR nBarCounter = 9 TO nStopCount
	sPrompt = PRMBAR("Window", nBarCounter)
	IF SUBSTR(sPrompt,AT(" ",sPrompt)+1) == thisform.caption
		nRemoveBar = nBarCounter
	ELSE
		IF nRemoveBar != 0 AND nBarCounter > nRemoveBar
			DEFINE BAR nBarCounter - 1 OF Window PROMPT TRANSFORM(nBarCounter - 9) + SUBSTR(sPrompt,AT(" ",sPrompt))
		endif
	endif
ENDFOR

RELEASE BAR nStopCount OF Window

IF nStopCount = 9
	RELEASE BAR 8 OF Window
endif

************************************
*!* The following needs to be placed in your procedure file (prg)
 PROCEDURE FormSelect (sPrompt)
	LOCAL nCounter, nFormCount
	
	sPrompt = ALLTRIM(SUBSTR(sPrompt, AT(" ", sPrompt) + 1))
	nFormCount = _Screen.formcount
	FOR nCounter =  1 TO nFormCount
		IF ALLTRIM(_screen.forms(nCounter).caption) == sPrompt
			_screen.forms(nCounter).windowstate = 0
			_screen.forms(nCounter).show(2)
		endif
	endfor
endproc


boyd.gif

[sub]craig1442@mchsi.com[/sub][sup]
"Whom computers would destroy, they must first drive mad." - Anon​
[/sup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top