如何在给定容器中启动进程? (如何在组框中启动 acrobate reader?)在 VB.Net 中

发布于 2024-12-04 17:45:53 字数 248 浏览 2 评论 0原文

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

有办法做到这一点吗?

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

例如,我没有找到允许我这样做的 .Parent 属性。 如果您有想法,请告诉我。

提前致谢。


I would like to have a preview of pdf and xps files displayed in my application. So I would like to be able to run a process and give it the "location" or the container where it should run from.


Is there anyway to do that?


I presently can launch whatever application I want, with the necessary ProcessStartInfo to open the file, but I would need the application to be contained within a particular control, rather than being a standalone application.


I didn't find a .Parent property for example, that would allow me to do it.
If you have an idea, let me know.


Thanks in advance.


如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我三岁 2024-12-11 17:45:53

一些发现:

首先在这里:http://www. dreamincode.net/forums/topic/148658-embedding-another-program-into-app/

第一个解决方案:使用网络浏览器控件:

  WebBrowser1.Url = New System.Uri("file://" & myFileNameHere)

第二个解决方案(在这里找到: http://www.tek-tips.com/viewthread.cfm?qid=1598720

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)

上面的代码正在运行,并且可能会得到改进。
我还在努力呢!

Some findings:

first here: http://www.dreamincode.net/forums/topic/148658-embedding-another-program-into-app/

first solution: use a webbrowser control with:

  WebBrowser1.Url = New System.Uri("file://" & myFileNameHere)

Second solution (found here: http://www.tek-tips.com/viewthread.cfm?qid=1598720 )

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)

The code above, is working and could probably be improved.

I'm stilling working on it!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文