一些研究結果:
先在這裏: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