I now want to add a new menu item - the "Window" one that is part of the
system menu. Really just want them to be able to see a list of open windows
and possibly have option to cascade them. I don't want the other stuff
(data session, command window etc.)
Here's what I do:
After you generate your menu file (*.mpr), edit it and go to the location
among the "DEFINE PAD" expressions where you want your Window menu to
appear. At that point, add:
DO MakeWindowMenu WITH cMenuName
(cMenuName is automatically initialized by the Menu Generator.)
Then you need a .prg file which needs to be accessible in your project (I
do it with SET PROCEDURE TO ... ADDITIVE). In this .prg file you need the
following two procedures:
PROCEDURE MakeWindowMenu
** This procedure manages the process of constructing menu pads on
the fly. It calls a
** method to handle Add-In Module menus, and then constructs a custom
Windows menu pad.
**
** This Windows pad gets around the native VFP Windows pad's
undesirable behaviors,
** including adding bars to itself at runtime that I've excluded in
the Menu Designer.
** This Windows pad includes the native Cascade, Arrange All, and
Cycle options, and it
** also maintains a list of open child windows.
**
** This procedure is based on code posted to the
microsoft.public.fox.programmer.exchange
** newsgroup by Neil McKamey on April 27, 1999. His code contained
errors, however. I have
** corrected them and modified the procedure for my needs.
**
** REQUIRES: FillWindowMenu() function (see below).
**
** NOTE: This method MUST be called from each menu .mpr program after
that program DEFINEs
** the Tools or System POPUP (it comes just before the Help
pad). That means that the
** call to this program MUST BE RE-INSERTED AFTER EVERY MENU
GENERATION!
**
** RETURNS: Nothing.
* Parameters:
*
* cMenuName - The name assigned to the menu by its .mpr file, as
generated by the Menu
* Designer. REQUIRED.
LPARAMETERS cMenuName
DEFINE PAD "WindowMenu" OF (cMenuName) PROMPT "\<Window" KEY ALT+W
ON PAD "WindowMenu" OF (cMenuName) ACTIVATE POPUP "WindowMenu"
DEFINE POPUP "WindowMenu" MARGIN SHADOW
DEFINE BAR _mwi_cascade OF "WindowMenu" PROMPT "Ca\<scade" ;
PICTRES _mwi_cascade ;
MESSAGE "Arranges windows as cascading tiles"
DEFINE BAR _mwi_arran OF "WindowMenu" PROMPT "\<Arrange All" ;
PICTRES _mwi_arran ;
MESSAGE "Arranges windows as non-overlapping tiles"
DEFINE BAR _mwi_rotat OF "WindowMenu" PROMPT "C\<ycle" ;
KEY CTRL+F1, "Ctrl+F1" ;
PICTRES _mwi_rotat ;
MESSAGE "Cycles through all open windows"
* (Comment in original McKamey code) The skip clause is attached to
the bar instead of the
* pad because the pad's skip clause is checked a lot of extra times.
DEFINE BAR 4 OF "WindowMenu" PROMPT "" SKIP FOR fillWindowMenu()
ENDPROC
FUNCTION FillWindowMenu
** This method updates the custom Windows menu with a list of the
captions of all open
** child windows. It is called by the MakeWindowMenu() procedure,
above, each time the
** user opens the Windows menu pad.
**
** This procedure is based on code posted to the
microsoft.public.fox.programmer.exchange
** newsgroup by Neil McKamey on April 27, 1999. His code contained
errors, however. I have
** corrected them and modified the procedure for my needs.
**
** NOTES: 1. I was unable to get a hotkey based on the number of the
window (derived from
** barnum), like those that appear in the native VFP Window
menu, to work. No
** combination of macro or variable expressions, including
saving the entire
** DEFINE BAR command as a macro and executing it, could
get the required KEY ...
** expression to work; all attemps threw syntax or variable
not found errors.
**
** RETURNS: .F. always (this is required for the SKIP FOR clause in
the default BAR 1
** definition).
LOCAL x, thecommand, barnum, somefound
x = 0 && Loop counter for open windows
somefound = .F. && Flag that indicates there were one or more open
visible child windows
barnum = 0 && Number of the bar that contains a specific window
caption
thecommand = "" && Command to Show() a particular open window
* Clear the menu to get rid of references to windows that are no
longer open.
RELEASE BAR ALL OF "WindowMenu"
* Restore the native options that we want.
DEFINE BAR _mwi_cascade OF "WindowMenu" PROMPT "Ca\<scade" ;
PICTRES _mwi_cascade ;
MESSAGE "Arranges windows as cascading tiles"
DEFINE BAR _mwi_arran OF "WindowMenu" PROMPT "\<Arrange All" ;
PICTRES _mwi_arran ;
MESSAGE "Arranges windows as non-overlapping tiles"
DEFINE BAR _mwi_rotat OF "WindowMenu" PROMPT "C\<ycle" ;
KEY CTRL+F1, "Ctrl+F1" ;
PICTRES _mwi_rotat ;
MESSAGE "Cycles through all open windows"
FOR x = _SCREEN.FormCount TO 1 STEP -1
* Don't include hidden forms or the application's Main Window in
the list.
IF (NOT _SCREEN.Forms[x].Visible) OR ;
UPPER(_SCREEN.Forms[x].Name) == "MAINWINDOW"
LOOP
ELSE
somefound = .T.
ENDIF
barnum = barnum + 1
thecommand = "_SCREEN.Forms[" + STR(x) + "].Show()"
IF barnum = 1
DEFINE BAR barnum OF "WindowMenu" ;
PROMPT TRANSFORM(barnum) + " " +
_SCREEN.Forms[x].Caption ;
SKIP FOR FillWindowMenu()
ELSE
DEFINE BAR barnum OF "WindowMenu" PROMPT TRANSFORM(barnum)
+ " " + ;
_SCREEN.Forms[x].Caption
ENDIF
ON SELECTION BAR barnum OF "WindowMenu" &thecommand
ENDFOR
IF somefound
* Add any additional window management items to the menu here.
ELSE
DEFINE BAR 1 OF "WindowMenu" PROMPT "" SKIP FOR FillWindowMenu()
ENDIF
RETURN .F.
ENDFUNC
Ken Dibble
www.stic-cil.org
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message:
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.