﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » .NET Forums » General .NET Discussion  » Hosting a VFP App</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Mon, 18 May 2026 09:00:57 GMT</lastBuildDate><ttl>20</ttl><item><title>Hosting a VFP App</title><link>http://forum.strataframe.net/FindPost5769.aspx</link><description>&lt;FONT size=2&gt;&lt;P&gt;&lt;FONT color=#111111&gt;I am trying to host an VFP application (MDI application withing the _screen) in .NET.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#111111&gt;What am I doing wrong below?&amp;nbsp; When I run this and step into the Process.Start method, everything works fine.&amp;nbsp; However, when I run the code without a break-point, the VFP Application is not hosted.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#111111&gt;A second question is: What would be the best practice in managing the process?&amp;nbsp; In other words: I would like the hosted application to terminate when the .NET app is exited.&amp;nbsp; Currently, unless I close the VFP app 1st, it is left in the running process collection (task manager).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#111111&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[codesnippet]&lt;/P&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Private&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/FONT&gt;&lt;FONT size=2&gt; DocMgrToolStripMenuItem_Click(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ByVal&lt;/FONT&gt;&lt;FONT size=2&gt; sender &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; System.Object, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ByVal&lt;/FONT&gt;&lt;FONT size=2&gt; e &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; System.EventArgs) &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Handles&lt;/FONT&gt;&lt;FONT size=2&gt; DocMgrToolStripMenuItem.Click&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; AppPath &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;String&lt;/FONT&gt;&lt;FONT size=2&gt; = &lt;/FONT&gt;&lt;FONT color=#800000 size=2&gt;"c:\MyVfpAppFolder\"&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; App2Run &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;String&lt;/FONT&gt;&lt;FONT size=2&gt; = &lt;/FONT&gt;&lt;FONT color=#800000 size=2&gt;"MyGreatFoxProApp.exe"&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; loStart &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;New&lt;/FONT&gt;&lt;FONT size=2&gt; System.Diagnostics.ProcessStartInfo(AppPath + App2Run)&lt;/P&gt;&lt;P&gt;loStart.WindowStyle = Diagnostics.ProcessWindowStyle.Normal&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;'loStart.UseShellExecute = False&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;loStart.WorkingDirectory = AppPath&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; oProcess &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; System.Diagnostics.Process = System.Diagnostics.Process.Start(loStart)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;'oProcess.WaitForInputIdle(3000)&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Do&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;While&lt;/FONT&gt;&lt;FONT size=2&gt; oProcess.MainWindowHandle.ToInt32() = 0&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Loop&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; lnHandle &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Integer&lt;/FONT&gt;&lt;FONT size=2&gt; = oProcess.MainWindowHandle.ToInt32()&lt;/P&gt;&lt;P&gt;SetParent(lnHandle, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.Handle)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/P&gt;&lt;/FONT&gt;&lt;P&gt;[/codesnippet]&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Tue, 06 Feb 2007 08:11:41 GMT</pubDate><dc:creator>Troy Murphy</dc:creator></item><item><title>RE: Hosting a VFP App</title><link>http://forum.strataframe.net/FindPost6577.aspx</link><description>Hey Troy,&lt;/P&gt;&lt;P&gt;I&amp;nbsp;am glad that you are getting this going.&amp;nbsp; I am sure that you have learned that there are some frustrations making the two talk, but at least there is a solution!&lt;/P&gt;&lt;P&gt;As for your question, it just looks to me like you are attempting to reference the _UDP variable before it has been referenced.&lt;/P&gt;&lt;P&gt;Generally you should never directly reference a variable in another class like this.&amp;nbsp; Instead of making the _UDP property public, you should leave this private and then create a public property that exposes this variable.&amp;nbsp; You can also make it shared so you do not have to have a direct reference to the main form.&amp;nbsp; This will also require that the variable is shared and will require all of your current referneces as well to reference the shared property rather than the internal variable.&lt;BR&gt;&lt;BR&gt;[codesnippet]Private Shared _UDP As UDPSession&lt;BR&gt;Public Shared ReadOnly Property UDP As UDPSession&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Make sure the UDP object has been created&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If _UDP Is Nothing&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _UDP = New UDPSession(...)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Get&lt;BR&gt;End Property[/codesnippet]&lt;/P&gt;&lt;P&gt;If you choose not to make the property shared and are going to just pass over a reference to any form that references the UDP property then the property would look something like this:&lt;/P&gt;&lt;P&gt;[codesnippet]Private _UDP As UDPSession&lt;BR&gt;Public ReadOnly Property UDP As UDPSession&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Get&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '-- Make sure the UDP object has been created&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If _UDP Is Nothing&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _UDP = New UDPSession(...)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Get&lt;BR&gt;End Property[/codesnippet]</description><pubDate>Tue, 06 Feb 2007 08:11:41 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Hosting a VFP App</title><link>http://forum.strataframe.net/FindPost6571.aspx</link><description>Very impressive - I must say!&amp;nbsp; I wish there was a shortcut to learning the .NET stuff.&amp;nbsp; &lt;P&gt;Anyway, using your provided example I have been able to test most of the needed functionality, but I do have a question on the UDP communication:&amp;nbsp; If I&amp;nbsp;send a message&amp;nbsp;via MyMainForm&amp;nbsp;(I made the UDP stuff public) in the sample &lt;STRONG&gt;CHILD&lt;/STRONG&gt; .NET form as below - an&amp;nbsp;"Object reference not set to an&amp;nbsp;instance..."&amp;nbsp;exception occurs at the "&lt;FONT size=2&gt;_UDP.Send(..." line in &lt;/FONT&gt;SendMessage method of UdpSession.vb&amp;nbsp;and the _UDP object is null.&amp;nbsp; &lt;/P&gt;&lt;P&gt;Obviously I am trying to leverage the code from MyMainForm to pass messages to and from&amp;nbsp;both applications.&amp;nbsp; Is this going about it the wrong way?&amp;nbsp; &lt;/P&gt;&lt;P&gt;[CodeSnippet]&lt;/P&gt;&lt;FONT size=2&gt;&lt;P&gt;MyMainForm._UDP.SendMessage(UDPMessageType.VisualFoxProCommand, &lt;/FONT&gt;&lt;FONT color=#800000 size=2&gt;"ChangeActiveCaseTo('"&lt;/FONT&gt;&lt;FONT size=2&gt; + CaseNo + &lt;/FONT&gt;&lt;FONT color=#800000 size=2&gt;"')"&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;[/CodeSnippet]&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Mon, 05 Feb 2007 16:10:39 GMT</pubDate><dc:creator>Troy Murphy</dc:creator></item><item><title>RE: Hosting a VFP App</title><link>http://forum.strataframe.net/FindPost5954.aspx</link><description>Thanks!&lt;/P&gt;&lt;P&gt;I look forward to digesting it.&amp;nbsp; I think I was making progress, but I am sure your tecnhiques are much more robust and certainly better tested...</description><pubDate>Fri, 19 Jan 2007 09:35:17 GMT</pubDate><dc:creator>Troy Murphy</dc:creator></item><item><title>RE: Hosting a VFP App</title><link>http://forum.strataframe.net/FindPost5904.aspx</link><description>I went ahead and stopped and created the .NET with embedded VFP EXE sample.&amp;nbsp; You can get to it here:&lt;/P&gt;&lt;P&gt;&lt;A href="http://forum.strataframe.net/Topic5903-17-1.aspx"&gt;http://forum.strataframe.net/Topic5903-17-1.aspx&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if you have any questions.&amp;nbsp; This should give you a great starting point.</description><pubDate>Wed, 17 Jan 2007 12:43:16 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Hosting a VFP App</title><link>http://forum.strataframe.net/FindPost5897.aspx</link><description>I am trying to follow your lead in using the Dart UDP control to establish a communication channel between the .NET and the VFP application.&amp;nbsp; Please tell me what I am doing wrong here.&amp;nbsp; &lt;P&gt;I think&amp;nbsp;the port is&amp;nbsp;opened correctly since the Receive event fires, but nothing seem to happen!&amp;nbsp; The receive parameters (passed by reference)&amp;nbsp;do not get populated.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face=Arial color=#111111&gt;This is the VFP snippet (Dart Control Receive Event):&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;[CodeSnippet]&lt;/P&gt;&lt;FONT face="Courier New"&gt;&lt;P&gt;lcString=&lt;/FONT&gt;&lt;FONT face="Courier New" color=#0000ff&gt;SPACE&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;(1024)&lt;/P&gt;&lt;P&gt;luRemoteIp=&lt;/FONT&gt;&lt;FONT face="Courier New" color=#0000ff&gt;SPACE&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;(40)&lt;/P&gt;&lt;P&gt;luRemotePort=1E9&lt;/P&gt;&lt;P&gt;llRetVlu=&lt;/FONT&gt;&lt;FONT face="Courier New" color=#0000ff&gt;thisform&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;.oleDartUdp.receive(@lcString,@luRemoteIp,@luRemotePort)&lt;/P&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" color=#0000ff&gt;&lt;P&gt;thisform&lt;/FONT&gt;&lt;FONT face="Courier New" color=#000000&gt;.edit1.&lt;/FONT&gt;&lt;FONT face="Courier New" color=#0000ff&gt;Value&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#000000&gt;=lcString&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#000000&gt;[/CodeSnippet]&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face=Arial color=#000000&gt;&lt;STRONG&gt;The .NET Sender Method&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#000000&gt;[CodeSnippet]&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#000000&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Dim&lt;/FONT&gt; sendbuf &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Byte&lt;/FONT&gt;() = Encoding.ASCII.GetBytes(&lt;FONT color=#0000ff&gt;Me&lt;/FONT&gt;.txtDataGram.Text.Trim())&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Dim&lt;/FONT&gt; oUDP &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; UdpClient = &lt;FONT color=#0000ff&gt;New&lt;/FONT&gt; UdpClient()&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Dim&lt;/FONT&gt; iRet &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; Int32 = oUDP.Send(sendbuf, sendbuf.Length, &lt;FONT color=#0000ff&gt;Me&lt;/FONT&gt;.txtIP.Text, &lt;FONT color=#0000ff&gt;Me&lt;/FONT&gt;.txtPort.Text)&lt;/P&gt;&lt;P&gt;[/CodeSnippet]&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;</description><pubDate>Wed, 17 Jan 2007 10:03:11 GMT</pubDate><dc:creator>Troy Murphy</dc:creator></item><item><title>RE: Hosting a VFP App</title><link>http://forum.strataframe.net/FindPost5813.aspx</link><description>As for your code having the extra lines inserted, it's the silly Javascript-based HTML editor that this forum uses.&amp;nbsp; You can try to post your code within [codesnippet][/codesnippet] brackets, and that might help... otherwise, you might try posting it within the HTML view&amp;nbsp;rather than the Design view.</description><pubDate>Mon, 15 Jan 2007 10:00:41 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Hosting a VFP App</title><link>http://forum.strataframe.net/FindPost5812.aspx</link><description>You will probably have to use that same loop to test on whether the VFP application is ready to host, but within the loop you can use Thread.SpinWait()... it's more efficient for pausing the current thread without chewing up processor cycles than sleeping or an empty loop is.&lt;/P&gt;&lt;P&gt;I believe we set the start position of our _Screen to be some set of coordinates that is assured to be off screen so that the form can popup and we can process some UI stuff on it before we move it to be hosted within the MDI &amp;#119;indow.&amp;nbsp; That should help remove some of the flickering and unsightlyness.&lt;/P&gt;&lt;P&gt;The problem is that the VFP _Screen is not exactly meant to be an MDI child.&amp;nbsp; So, when you resize the MDI container, the _Screen doesn't get resized.&amp;nbsp; We have to send a resize command over the UDP listener between the processes to resize the _Screen when the MDI container is resized.&lt;/P&gt;&lt;P&gt;And yes, we just Process.Kill() the VFP process when .NET exits.&amp;nbsp; We also have a listener on an error event from FoxPro so that if an unexpected error occurs within the VFP process, the .NET process knows that it needs to exit as well.</description><pubDate>Mon, 15 Jan 2007 09:59:17 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Hosting a VFP App</title><link>http://forum.strataframe.net/FindPost5783.aspx</link><description>&lt;FONT color=#111111&gt;Ok, Making progress...&amp;nbsp; I hope you are patient with my total overwhelmed attempt to master .NET. &lt;/FONT&gt;&lt;P&gt;&lt;FONT color=#111111&gt;Actually the main problem was that I had to sleep the&amp;nbsp;thread&amp;nbsp;after the process.start (the loop watching the window handle did nothing but lock the application indefinitely).&amp;nbsp; Anyway, I can't help but think there must be a better way since the sleep command is flaky based on the speed of application launch.&amp;nbsp; Setting it too high is&amp;nbsp;a significant performance loss - and an apparent interface freeze, but setting it too low and the VFP app does not become hosted.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#111111&gt;A related issue is: I would like the VFP app to be in the proper state before making it visible.&amp;nbsp; Currently a lot of window activity is going on which is very ugly!&amp;nbsp; I tried to set the ProcessStartInfo instance to hidden, but that did nothing.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#111111&gt;Another problem I am having is on the resize:&amp;nbsp; Can you tell me why I get scrollbars in the _MDI region when I resize the form?&amp;nbsp; How do I remove them?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#111111&gt;Last, but not least (at least for now): What is the best way of having the hosted VFP app shutdown when the .NET form is closing?&amp;nbsp; Here I am killing the process, but I don't suspect that is the recommended way of doing this!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;[CodeSnippet]&lt;/P&gt;&lt;FONT color=#0000ff&gt;&lt;P&gt;Public&lt;/FONT&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff&gt;Class&lt;/FONT&gt;&lt;FONT color=#000000&gt; Form1&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Declare&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Function&lt;/FONT&gt; ShowWindow &lt;FONT color=#0000ff&gt;Lib&lt;/FONT&gt; &lt;FONT color=#800000&gt;"user32"&lt;/FONT&gt; (&lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; hWnd &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; System.IntPtr, &lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; nCmdShow &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Integer&lt;/FONT&gt;) &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Boolean&lt;/P&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Declare&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Function&lt;/FONT&gt; SetParent &lt;FONT color=#0000ff&gt;Lib&lt;/FONT&gt; &lt;FONT color=#800000&gt;"user32"&lt;/FONT&gt; (&lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; hWndChild &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; System.IntPtr, &lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; hWndNewParent &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; System.IntPtr) &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; System.IntPtr&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Declare&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Function&lt;/FONT&gt; SetForegroundWindow &lt;FONT color=#0000ff&gt;Lib&lt;/FONT&gt; &lt;FONT color=#800000&gt;"user32"&lt;/FONT&gt; (&lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; hwnd &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; System.IntPtr) &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Integer&lt;/P&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Declare&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Function&lt;/FONT&gt; SetWindowPos &lt;FONT color=#0000ff&gt;Lib&lt;/FONT&gt; &lt;FONT color=#800000&gt;"user32"&lt;/FONT&gt; (&lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; hWnd &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Integer&lt;/FONT&gt;, &lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; hWndInsertAfter &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Integer&lt;/FONT&gt;, &lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; X &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Integer&lt;/FONT&gt;, &lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; Y &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Integer&lt;/FONT&gt;, &lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; cx &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Integer&lt;/FONT&gt;, &lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; cy &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Integer&lt;/FONT&gt;, &lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; uFlags &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Integer&lt;/FONT&gt;) &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Boolean&lt;/P&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Dim&lt;/FONT&gt; _Mdi &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; MdiClient&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Dim&lt;/FONT&gt; _MdiClientHandle &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Integer&lt;/P&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Dim&lt;/FONT&gt; _Processes &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; Collection = &lt;FONT color=#0000ff&gt;New&lt;/FONT&gt; Collection()&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Private&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Sub&lt;/FONT&gt; DocMgrToolStripMenuItem_Click(&lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; sender &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; System.Object, &lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; e &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; System.EventArgs) &lt;FONT color=#0000ff&gt;Handles&lt;/FONT&gt; DocMgrToolStripMenuItem.Click&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Dim&lt;/FONT&gt; AppPath &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;String&lt;/FONT&gt; = &lt;FONT color=#800000&gt;"c:\MyVfpApp\"&lt;/P&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Dim&lt;/FONT&gt; App2Run &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;String&lt;/FONT&gt; = &lt;FONT color=#800000&gt;"TheBestVfpAppEver.exe"&lt;/P&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;If&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Not&lt;/FONT&gt; _Processes.Contains(App2Run) &lt;FONT color=#0000ff&gt;Then&lt;/P&gt;&lt;/FONT&gt;&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Dim&lt;/FONT&gt; loStart &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;New&lt;/FONT&gt; System.Diagnostics.ProcessStartInfo(AppPath + App2Run)&lt;/P&gt;&lt;P&gt;loStart.WorkingDirectory = AppPath&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Dim&lt;/FONT&gt; oProcess &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; System.Diagnostics.Process = System.Diagnostics.Process.Start(loStart)&lt;/P&gt;&lt;P&gt;System.Threading.Thread.Sleep(5000)&lt;/P&gt;&lt;P&gt;_MdiClientHandle = oProcess.MainWindowHandle.ToInt32()&lt;/P&gt;&lt;P&gt;SetParent(_MdiClientHandle, _Mdi.Handle)&lt;/P&gt;&lt;P&gt;SetWindowPos(_MdiClientHandle, 0, 0, 0, _Mdi.Width, _Mdi.Height, &amp;amp;H20)&lt;/P&gt;&lt;P&gt;_Processes.Add(oProcess, App2Run)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Else&lt;/P&gt;&lt;/FONT&gt;&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;&lt;P&gt;MsgBox(App2Run + &lt;FONT color=#800000&gt;" is already open."&lt;/FONT&gt;)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;End&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;If&lt;/P&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;End&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Sub&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Private&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Sub&lt;/FONT&gt; Form1_Load(&lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; sender &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; System.Object, &lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; e &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; System.EventArgs) &lt;FONT color=#0000ff&gt;Handles&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;MyBase&lt;/FONT&gt;.Load&lt;/P&gt;&lt;P&gt;_Mdi = &lt;FONT color=#0000ff&gt;New&lt;/FONT&gt; MdiClient()&lt;/P&gt;&lt;P&gt;_Mdi.BackColor = System.Drawing.Color.White&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Me&lt;/FONT&gt;.IsMdiContainer = &lt;FONT color=#0000ff&gt;True&lt;/P&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Me&lt;/FONT&gt;.Controls.Add(_Mdi)&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;End&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Sub&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Private&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Sub&lt;/FONT&gt; Form1_FormClosing(&lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; sender &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; System.Object, &lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; e &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; System.Windows.Forms.FormClosingEventArgs) &lt;FONT color=#0000ff&gt;Handles&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;MyBase&lt;/FONT&gt;.FormClosing&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;For&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Each&lt;/FONT&gt; oProcess &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; System.Diagnostics.Process &lt;FONT color=#0000ff&gt;In&lt;/FONT&gt; _Processes&lt;/P&gt;&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;If&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Not&lt;/FONT&gt; oProcess.HasExited &lt;FONT color=#0000ff&gt;Then&lt;/P&gt;&lt;/FONT&gt;&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;&lt;P&gt;oProcess.Kill()&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;End&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;If&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Next&lt;/P&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;End&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Sub&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;Private&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Sub&lt;/FONT&gt; Form1_SizeChanged(&lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; sender &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; System.Object, &lt;FONT color=#0000ff&gt;ByVal&lt;/FONT&gt; e &lt;FONT color=#0000ff&gt;As&lt;/FONT&gt; System.EventArgs) &lt;FONT color=#0000ff&gt;Handles&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;MyBase&lt;/FONT&gt;.SizeChanged&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;If&lt;/FONT&gt; _MdiClientHandle &amp;gt; 0 &lt;FONT color=#0000ff&gt;Then&lt;/P&gt;&lt;/FONT&gt;&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;&lt;P&gt;SetWindowPos(_MdiClientHandle, 0, 0, 0, _Mdi.Width, _Mdi.Height, &amp;amp;H20)&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;End&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;If&lt;/P&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;End&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;Sub&lt;/P&gt;&lt;P&gt;End&lt;/FONT&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff&gt;Class&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;[/CodeSnippet]&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;&lt;FONT color=#111111&gt;Also: Why does my code sample insist on adding blank lines between each pasted line of code?&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Fri, 12 Jan 2007 12:41:20 GMT</pubDate><dc:creator>Troy Murphy</dc:creator></item><item><title>RE: Hosting a VFP App</title><link>http://forum.strataframe.net/FindPost5773.aspx</link><description>So, the VFP process is started, but the _Screen never gets into the MDI container?&lt;/P&gt;&lt;P&gt;I think you need to change the second parameter in the SetParent() call from Me.Handle to Me.mdiContainer.Handle so that the screen gets hosted in the MDI container.&amp;nbsp; A basic .NET form does not have the necessary Win32 properties set for it to host other forms, so you have to have an MDI container.&amp;nbsp; &lt;/P&gt;&lt;P&gt;If you're taking a form and setting the IsMdiContainer property to True, then it's not really an MDI container... .NET adds an MdiClient control to the form for you... We have a private variable on the form that holds the MdiClient reference and then initialize it in the New().&lt;/P&gt;&lt;FONT color=#010001 size=1&gt;&lt;P&gt;_Mdi&lt;/FONT&gt;&lt;FONT color=#000000 size=1&gt; = &lt;/FONT&gt;&lt;FONT color=#0000ff size=1&gt;New&lt;/FONT&gt;&lt;FONT color=#000000 size=1&gt; &lt;/FONT&gt;&lt;FONT color=#010001 size=1&gt;MdiClient&lt;/FONT&gt;&lt;FONT size=1&gt;&lt;FONT color=#000000&gt;()&lt;BR&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#010001 size=1&gt;_Mdi&lt;/FONT&gt;&lt;FONT size=1&gt;.&lt;/FONT&gt;&lt;FONT color=#010001 size=1&gt;BackColor&lt;/FONT&gt;&lt;FONT size=1&gt; = &lt;/FONT&gt;&lt;FONT color=#010001 size=1&gt;System&lt;/FONT&gt;&lt;FONT size=1&gt;.&lt;/FONT&gt;&lt;FONT color=#010001 size=1&gt;Drawing&lt;/FONT&gt;&lt;FONT size=1&gt;.&lt;/FONT&gt;&lt;FONT color=#010001 size=1&gt;Color&lt;/FONT&gt;&lt;FONT size=1&gt;.&lt;/FONT&gt;&lt;FONT color=#010001 size=1&gt;White&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=1&gt;Me&lt;/FONT&gt;&lt;FONT size=1&gt;.&lt;/FONT&gt;&lt;FONT color=#010001 size=1&gt;Controls&lt;/FONT&gt;&lt;FONT size=1&gt;.&lt;/FONT&gt;&lt;FONT color=#010001 size=1&gt;Add&lt;/FONT&gt;&lt;FONT size=1&gt;(&lt;/FONT&gt;&lt;FONT color=#010001 size=1&gt;_Mdi&lt;/FONT&gt;&lt;FONT size=1&gt;)&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=1&gt;Me&lt;/FONT&gt;&lt;FONT size=1&gt;.&lt;/FONT&gt;&lt;FONT color=#010001 size=1&gt;IsMdiContainer&lt;/FONT&gt;&lt;FONT size=1&gt; = &lt;/FONT&gt;&lt;FONT color=#0000ff size=1&gt;True&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff size=1&gt;&lt;FONT color=#1f5080 size=2&gt;When you call SetParent(), you then pass the _Mdi.Handle as the second parameter.&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Thu, 11 Jan 2007 16:45:08 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item></channel></rss>