WEEK()

WChild(), WParent()

These functions let you figure out who's who among the window set. WCHILD() lets you find the child windows of a window, while WPARENT() gives you the parent window. Like most of the other window functions, we don't use these much anymore because we don't define our own windows—we use forms.

Usage

cParentWindow = WPARENT( [ cWindowName ] ) nChildCount = WCHILD( [ cWindowName ] ) cNextChild = WCHILD( [ cWindowName, ]  nCounter )

Parameter

Value

Meaning

cWindowName

Character

The window about which you want parent or child information.

Omitted

Return information about the current output window.

cParentWindow

Character

The name of the parent window of the specified window.

Empty

The specified window sits right in the main Visual FoxPro window.

nChildCount

Numeric

The number of child windows for the specified window.

nCounter

0

Return the name of the first child window.

Any other number

Return the name of the next child window—the first call with nCounter included returns the first child.

cNextChild

Character

The name of the next child window of the specified window.

Empty

There are no more child windows for the specified window.


All windows that aren't defined IN some other window and aren't defined IN DESKTOP are children of the main Visual FoxPro window. So are undocked toolbars. WPARENT() returns the empty string for such windows. Windows defined IN DESKTOP have no parent, and again, WPARENT() returns the empty string.

WCHILD() is a weird function. When you omit the numeric parameter, it's simple enough. It tells you how many children a particular window has. But when you pass a number, it's downright strange. It lets you go through the list of children, but it's kind of touchy.

Here's the story. Pass 0 and you get the "first" child window—the child that's first on the list in the Window menu. Pass any other number and you start cycling. Each time you call WCHILD() with any number other than 0, you get the next child window. You get the empty string as a return value when you're out of child windows. To go back to the beginning, you have to use WCHILD(0), but that counts as the first call, and the next WCHILD() call with anything other than 0 continues cycling. Be sure to save the result whenever you call WCHILD() with a number, because the cycling process means you won't get the same window again (except for successive calls to WCHILD(0)).

In VFP 5.0a and earlier, issuing a series of calls to WCHILD(<number>) on a window other than the main VFP window runs out of windows too soon. The last child window doesn't get reported.


To get children of the main Visual FoxPro window, either ACTIVATE SCREEN or pass the name of the main window. FoxPro is actually pretty flexible about what you can pass here: "SCREEN" works; so does _SCREEN.Caption; and if you haven't changed the caption, "Microsoft" is effective, too. Of course, you could just use FormCount and the Forms collection of _SCREEN instead.

Example

* The most common thing to do is to loop through and find  * all the children. * This example works on the active window. nChildCnt = WCHILD() WAIT WINDOW "This window has " + ;             PADL(nChildCnt, 3) + " children." cChildName = WCHILD(0) DO WHILE NOT EMPTY(cChildName)    WAIT WINDOW "One child is " + cChildName    cChildName = WCHILD(1) ENDDO

See Also

Define Window, WTitle()


View Updates

Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.



Hacker's Guide to Visual FoxPro 7. 0
Hackers Guide to Visual FoxPro 7.0
ISBN: 1930919220
EAN: 2147483647
Year: 2001
Pages: 899

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net