PRB: Application Loses Focus or Opens Minimized on Startup
ID: Q178117
|
The information in this article applies to:
-
Microsoft Visual FoxPro for Windows, versions 5.0, 5.0a, 6.0
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
- 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
- From the command line, type the following:
DO RUNHIDE
- 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
- 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"
Additional query words:
Keywords : kbMAC kbVFp kbVFp500 kbVFp500a kbVFp600 FxprgClassoop
Version : WINDOWS:5.0,5.0a,6.0
Platform : WINDOWS
Issue type : kbprb