开发者

How to start a process in a given container? (how to start acrobate reader in a groupbox?) in VB.Net

开发者 https://www.devze.com 2023-04-05 02:32 出处:网络
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.

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 necessa开发者_如何学Cry 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.


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消