PRB: Application Loses Focus or Opens Minimized on Startup

Last reviewed: December 22, 1997
Article ID: Q178117
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, versions 5.0, 5.0a

SYMPTOMS

When you launch a Visual FoxPro application, it appears to open minimized or loses focus.

CAUSE

This behavior occurs when you include the following code in the Init event of a Top-Level form:

   APPLICATION.VISIBLE=.F.

RESOLUTION

Move the following line:

   APPLICATION.VISIBLE=.F.

to the Activate event of the Top-Level form.

STATUS

This behavior is by design.

MORE INFORMATION

The line Application.Visible=.F. hides the main Visual FoxPro window. The reason the application loses focus and appears to open minimized is related to the sequence of events. Because the form's Init event sets the application's Visible property to false, the application is hidden and focus returns to the last active object or application. Even though the application no longer has focus, the code continues executing as a background process.

Steps to Reproduce Behavior

  1. To illustrate this behavior, create a program called Runhide.prg with the following code:

         LOST=CREATEOBJECT('NOFOCUS')
         LOST.SHOW
         READ EVENTS
         RETURN
    

         DEFINE CLASS nofocus AS FORM
         AUTOCENTER = .T.
         HEIGHT  = 450
    
         WIDTH   = 640
         CAPTION = "Lost Focus Form"
         VISIBLE = .T.
         SHOWWINDOW=2
         WINDOWTYPE=0
         ADD OBJECT frmcaption AS frmcap WITH Top=225, Left=220
         PROCEDURE INIT
         APPLICATION.VISIBLE=.F.
         ENDPROC
         PROCEDURE CLICK()
         THISFORM.RELEASE
         CLEAR EVENTS
         APPLICATION.VISIBLE=.T.
         ENDPROC
         ENDDEFINE
    
         DEFINE CLASS frmcap AS LABEL
         FONTNAME="ARIAL"
         FONTSIZE=10
         FONTBOLD=.T.
         CAPTION="Click anywhere on the form to close"
         VISIBLE=.T.
         AUTOSIZE=.T.
         ENDDEFINE
    
    

  2. From the command line, type the following:

          DO RUNHIDE
    

  3. To illustrate hiding the main Visual FoxPro window while the application retains focus, create a program called Nohide.prg with the following code:

         NOTLOST=CREATEOBJECT('HASFOCUS')
         NOTLOST.SHOW
         READ EVENTS
         RETURN
    

         DEFINE CLASS hasfocus AS FORM
         AUTOCENTER = .T.
         HEIGHT  = 450
    
         WIDTH   = 640
         CAPTION = "Lost Focus Form"
         VISIBLE = .T.
         SHOWWINDOW=2
         WINDOWTYPE=0
         ADD OBJECT frmcaption AS frmcap WITH Top=225, Left=220
         PROCEDURE ACTIVATE
         APPLICATION.VISIBLE=.F.
         ENDPROC
         PROCEDURE CLICK()
         THISFORM.RELEASE
         CLEAR EVENTS
         APPLICATION.VISIBLE=.T.
         ENDPROC
         ENDDEFINE
    
         DEFINE CLASS frmcap AS LABEL
         FONTNAME="ARIAL"
         FONTSIZE=10
         FONTBOLD=.T.
         CAPTION="Click anywhere on the form to close"
         VISIBLE=.T.
         AUTOSIZE=.T.
         ENDDEFINE
    
    

  4. From the command line, type the following:

          DO NOHIDE
    

REFERENCES

Visual FoxPro Help, version 5.00; search on: "Application" Visual FoxPro Help, version 5.00; search on: "Visible"

Keywords          : FxprgClassoop VFoxMac vfoxwin
Version           : WINDOWS:5.0,5.0a
Platform          : WINDOWS
Issue type        : kbprb


================================================================================


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: December 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.