Microsoft KB Archive/172560: Difference between revisions
(importing KB archive) |
m (Text replacement - """ to """) |
||
Line 59: | Line 59: | ||
<ol> | <ol> | ||
<li>In the Visual FoxPro Class Designer, create a class with a property to hold the window handle. Call the property | <li>In the Visual FoxPro Class Designer, create a class with a property to hold the window handle. Call the property "myHwind."</li> | ||
<li><p>In the Show Method of the Visual FoxPro Class, add the following code: <span class="kbd userinput"> </span></p> | <li><p>In the Show Method of the Visual FoxPro Class, add the following code: <span class="kbd userinput"> </span></p> | ||
<pre class="codesample"> SET LIBRARY TO HOME()+ | <pre class="codesample"> SET LIBRARY TO HOME()+"\foxtools.fll" && If FoxTools is in the Home | ||
&& directory. | && directory. | ||
Thisform.myHwind = mainhwnd() | Thisform.myHwind = mainhwnd() |
Revision as of 11:06, 21 July 2020
Article ID: 172560
Article Last Modified on 7/13/2004
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 Q172560
SUMMARY
If you create a local Visual FoxPro OLE Automation Server that displays a user interface (UI), the UI may not have focus when initiated. To force the Visual FoxPro OLE server to have focus you can call the SetForegroundWindow API from the client and pass the window handle of the Visual FoxPro OLE Server.
MORE INFORMATION
When calling the Show Method of a Visual FoxPro OLE Server from a client application, such as a Visual Basic executable, the Visual FoxPro UI may not receive focus.
Here is a method of forcing the Visual FoxPro OLE Server to have focus and control:
- In the Visual FoxPro Class Designer, create a class with a property to hold the window handle. Call the property "myHwind."
In the Show Method of the Visual FoxPro Class, add the following code:
SET LIBRARY TO HOME()+"\foxtools.fll" && If FoxTools is in the Home && directory. Thisform.myHwind = mainhwnd() SET LIBRARY TO
This code loads the Foxtools library and calls mainhwnd, which returns the window handle for the main Visual FoxPro window, in this case it would be your OLE Server Form. The code places the window handle into the class property myHwind and then releases the Foxtools library.
In the client, add the following code:
DECLARE Integer SetForegroundWindow in WIN32API long whnd ox.Show() whnd = ox.myHwind x = SetForegroundWindow(whnd)
This code assumes that the Visual FoxPro OLE server was instantiated elsewhere in the program using the Createobject command. This code uses the DECLARE as you would in Visual FoxPro; the syntax would be different in Visual Basic. The code then calls the Show Method. At this point, the UI for the OLE Server appears, but it does not have focus. Next get the window handle that was stored in as a class property, call SetForegroundWindow, and pass the window handle of the application to get focus.
REFERENCES
For more information about the SetForegroundWindow, please refer to the Win32 SDK
For more information about the Mainhwnd function, please refer to the Foxtools.hlp in the tools directory that is installed with Visual FoxPro.
(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by David Botzenhart, Microsoft Corporation
Additional query words: OLE
Keywords: kbhowto KB172560