1

Scott Beeson once posted the following code here to lauch an application inside an userform:

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

So I've tried to start Excel2007 and it worked, although not always stable. But Excel2010 doesn't open in the userform, just the normal way. I have two questions:

1) Has anyone maybe an idea how to get XL2010 working with this?

2) Any idea how to code this in a WPF mainwindow? 'Panel1.Handle' doesn't seem to exit there...

Filburt
  • 17,626
  • 12
  • 64
  • 115
  • This is simply a really bad idea. Whatever your reason for wanting to do this, I can almost guarantee that is is wrong. Explain what you are trying to do and there will be a better way. – J... Jan 19 '14 at 14:46
  • Bad idea, probably. My reason, testing how bad the idea is! Just let me find it out myself, please... – user2255312 Jan 20 '14 at 09:55
  • To help with the excel problem you'll have to provide more debugging information than *"it's not always stable"*. Embedding an application can be extremely problematic, particularly if either application does not process window messages in a timely manner. It sounds like you have a lot of reading to do before going any further with this project... http://stackoverflow.com/questions/6477851/how-to-run-an-application-inside-wpf-application --- http://msdn.microsoft.com/en-us/library/ms752055.aspx ---http://stackoverflow.com/questions/5028598/hosting-external-app-in-wpf-window --- – J... Jan 20 '14 at 11:13
  • Thanks a lot for the links. A lot of info there. I appreciate it. Don't worry about the problems and bugs I will encounter: reading all about it and findin out what the difficulties are, IS the project. "it is not always stable": Excel shows the ribbon, but sometime not. – user2255312 Jan 20 '14 at 12:48
  • Hey it worked really well for what I used it for!!! :) –  Jul 29 '14 at 16:52
  • And in case you're curious: http://stackoverflow.com/questions/13651815/vb-net-launch-application-inside-a-form?rq=1 –  Jul 29 '14 at 16:54

0 Answers0