在userform中启动应用程序

时间:2014-01-19 13:24:58

标签: wpf vb.net excel userform

Scott Beeson曾在此处发布以下代码,以便在用户表单中添加一个应用程序:

Public Class Form1
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 Const WM_SYSCOMMAND As Integer = 274
Private Const SC_MAXIMIZE As Integer = 61488
Dim proc As Process

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    proc = Process.Start("C:\WINDOWS\notepad.exe")
    proc.WaitForInputIdle()

    SetParent(proc.MainWindowHandle, Panel1.Handle)
    SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
    Me.BringToFront()
End Sub
End Class

所以我尝试启动Excel2007并且它有效,但并不总是稳定的。但Excel2010不会在用户窗体中打开,只是正常方式。我有两个问题:

1)有没有人知道如何让XL2010使用它?

2)知道如何在WPF主窗口中编写代码吗? 'Panel1.Handle'似乎没有退出......

0 个答案:

没有答案