一些研究结果:
先在这里:http://www.dreamincode.net/forums/topic/148658-embedding-another-program-into-app/
第一个解决方案:使用WebBrowser控件:
Private Const WM_SYSCOMMAND As Integer = 274
Private Const SC_MAXIMIZE As Integer = 61488
Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Sub Test3()
Try
myProcess.Kill()
Catch ex As Exception
Dim ii As Integer = 33
End Try
Dim valueFileName As String = myFileNameHere
Dim myProcessInfo As New ProcessStartInfo
myProcessInfo.FileName = myCompletePathToTheEXEFileHere
myProcessInfo.WorkingDirectory = valueFileName.Substring(0, valueFileName.LastIndexOf("\") + 1)
myProcessInfo.Arguments = valueFileName.Substring(valueFileName.LastIndexOf("\") + 1)
myProcess.StartInfo = myProcessInfo
myProcess.Start()
myProcess.WaitForInputIdle()
Threading.Thread.Sleep(500)
SetParent(myProcess.MainWindowHandle, Me.GroupBox1.Handle)
SendMessage(myProcess.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
:
WebBrowser1.Url = New System.Uri("file://" & myFileNameHere)
二溶液(http://www.tek-tips.com/viewthread.cfm?qid=1598720这里)
上面的代码正在工作,可能可以改进。
我正在努力工作!
有趣的问题,有趣的答案!我以前看过类似的东西,用于在应用程序中重新托管Word等,但从未知道它是如何完成的:) – Tom
webBrowser控件实际上非常强大:它打开大量文件(.doc,.xls,.csv, .ppt,.xps,.pdf等) – PatTheFrog
我在WebBrowser控件中发现了一个问题:您需要考虑为每个特定文件打开它打开的进程。因此,您可能需要添加一些代码,如下所示:http://bytes.com/topic/visual-basic-net/answers/538885-webbrowser-excel-processs-till-running,或者只需计算您的流程在打开文档之前和之后,每次打开新文档和处理控件时,请杀死额外的文档。 – PatTheFrog