Microsoft KB Archive/178117

= PRB: Application Loses Focus or Opens Minimized on Startup =

Article ID: 178117

Article Last Modified on 3/10/2001

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



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
  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  At a command prompt, type the following command:

DO RUNHIDE

  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  At a command prompt, type the following command:

DO NOHIDE



<div class="references_section">