2011-09-14 89 views
0

我想预览显示在我的应用程序中的pdf和xps文件。所以我希望能够运行一个进程并将其放在应该运行的“位置”或容器中。

有没有办法做到这一点?

我目前可以启动任何我想要的应用程序,并具有必要的ProcessStartInfo来打开文件,但是我需要将应用程序包含在特定控件中,而不是作为独立应用程序。

例如,我没有找到.Parent属性,这将允许我这样做。 如果你有一个想法,让我知道。

在此先感谢。


如何在给定的容器中启动进程? (如何启动在groupbox中的杂技阅读器?)在VB.Net

回答

1

一些研究结果:

先在这里: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这里)

上面的代码正在工作,可能可以改进。
我正在努力工作!

+0

有趣的问题,有趣的答案!我以前看过类似的东西,用于在应用程序中重新托管Word等,但从未知道它是如何完成的:) – Tom

+0

webBrowser控件实际上非常强大:它打开大量文件(.doc,.xls,.csv, .ppt,.xps,.pdf等) – PatTheFrog

+0

我在WebBrowser控件中发现了一个问题:您需要考虑为每个特定文件打开它打开的进程。因此,您可能需要添加一些代码,如下所示:http://bytes.com/topic/visual-basic-net/answers/538885-webbrowser-excel-processs-till-running,或者只需计算您的流程在打开文档之前和之后,每次打开新文档和处理控件时,请杀死额外的文档。 – PatTheFrog

相关问题