PRB: Application Loses Focus or Opens Minimized on Startup (178117)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 5.0
  • Microsoft Visual FoxPro for Windows 5.0a
  • Microsoft Visual FoxPro for Windows 6.0

This article was previously published under Q178117

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 "Application.Visible = .F." line 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. Create a program called Runhide.prg, and paste the following code:
    oLost = CREATEOBJECT('NOFOCUS')
    oLost.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. At a command prompt, type the following command:

    DO RUNHIDE

  3. To hide the main Visual FoxPro window while the application retains focus, create a program called Nohide.prg, and paste the following code:
    oNotLost = CREATEOBJECT('NOFOCUS')
    oNotLost.Show()
    READ EVENTS
    RETURN
    
    DEFINE CLASS hasFocus AS FORM
        AutoCenter = .T.
        Height  = 450
        Width   = 640
        Caption = "Has 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. At a command prompt, type the following command:

    DO NOHIDE

REFERENCES

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

Modification Type:MajorLast Reviewed:3/10/2001
Keywords:kbDSupport kbprb KB178117