How to Activate a Browse Window from a Push Button

Last reviewed: April 30, 1996
Article ID: Q124272
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6, 2.6a
  • Microsoft FoxPro for MS-DOS, versions 2.5, 2.5a, 2.5b, 2.6, 2.6a
  • Microsoft FoxPro for Macintosh, version 2.5b, 2.5c, 2.6

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: kbprg kbcode
KBSubcategory: FxprgBrowse


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 30, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.