How to Activate a Browse Window from a Push Button

ID: Q124272

2.50x 2.60 2.60a | 2.50x 2.60 2.60a | 2.50x 2.60

WINDOWS          | MS-DOS           | MACINTOSH

The information in this article applies to:

SUMMARY

It is possible to activate a Browse window from a push button on another window. This could be useful if you want an ADD button to append a record to the table, and then switch focus to the Browse window. This article shows by example how to do it.

MORE INFORMATION

The ACTIVATE WINDOW command will not work within the VALID procedure of a push button or any other @ ... GET. The VALID procedure keeps the user in the current GET until FoxPro knows the return value. Therefore, you cannot activate another window from within the VALID procedure because the current GET is still the _CUROBJ, and the _CUROBJ always puts its window on top.

For example, if you try to activate a Browse window from the VALID procdure of a push button, the Browse window will seem to flash for an instant; then focus will return to the GET window.

Therefore, to accomplish the task, you must stuff the keyboard buffer with a keystroke that will activate the Browse window. This could be a menu shortcut that does an ACTIVATE WINDOW <browse window> or it could be an ON KEY LABEL procedure. The keyboard buffer is processed when the VALID procedure is completed.

Code Sample

The following sample code uses the ON KEY LABEL approach and uses the customer table from the TUTORIAL directory. It draws two windows, a Browse on the left and a GET window with two buttons on the right. To try the sample, create a program (.PRG file) and type in the following code along with both procedures.

use customer define window one at 1,1 size 15,30 browse window one nowait title "Browse Window" define window two at 1,35 size 15,30 system title "Get Window" activate window two @ 2,2 get m.var default 1 picture '@*N Browse Window;Get Window' ;

   size 6,15 valid varval()
read cycle release window "Browse Window" release window one release window two

*Use the following procedure for the VALID procedure of the push buttons. *The first case statement (m.var=1) defines an ON KEY LABEL to run the *switchum procedure. The second case statement (m.var=2) defines the ON KEY *LABEL to do nothing. If you didn't use the asterisk, the macro assigned to *the F2 key would process at the end of the VALID procedure, which would *cause unexpected results. Place the KEYBOARD statement at the end of the *VALID procedure. It stuffs the keyboard with the ON KEY LABEL key right *before the VALID procedure returns.

procedure varval do case

   case m.var=1
      on key label f2 do switchum
   case m.var=2
      on key label f2 *
endcase keyboard "{f2}"

*The following procedure is called by the ON KEY LABEL. It activates the *Browse window, and then resets the F2 key so that the user does not *accidentally press it.

procedure switchum activate window "Browse Window" on key label f2 *

Additional reference words: FoxWin FoxDos FoxMac 2.50 2.50a 2.50b 2.50c 2.60 2.60a deactivate lost focus flicker KBCategory: KBSubcategory: FxprgBrowse

Keywords          : kbcode FxprgBrowse 
Version           : 2.50x 2.60 2.60a | 2.50x 2.60 2.
Platform          : MACINTOSH MS-DOS WINDOWS

Last Reviewed: May 22, 1998