• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 891
  • Last Modified:

Embed and Application in Vb.NET

Is there a way to launch an external process, say notepad or something and then embed that process as an embeded object on a form or panel?
0
steveo555
Asked:
steveo555
  • 7
  • 6
1 Solution
 
S-TwilleyCommented:
I've seen samples before which put an application into a panel... but from what I've seen in the comments, more complex applications don't work well when hosted ina panel... I think for other experts to be able to answer your question more clearly... you need to give more details about what kind of applications your hoping to host within your application, or what you're actually trying to achieve...

==================

on a side note... to start an extenal app.

Dim p as new Process
p.Startinfo.filename="C:\windows\notepad.exe"
p.start()

and I believe you can get the main window handle of said application with

p.mainwindowhandle
0
 
steveo555Author Commented:
Thanks for the quick reply. My application has many modules which open as new tabs so users can flick back on forth (like firefox). I need my application to be the only one people use (sort of a global system). If they need to launch a third party app I need it to launch within my app so I can embed it on a new tab in my app.i dont need to have control over the app I just need it to be neatly docked inside mine.

Eg.

Launch Notepad.exe or Outlook Express etc.

somehow dock it on a new panel

then add that panel to the controls collection of my new tab

when the tab is closed I stop the process.
0
 
S-TwilleyCommented:
If i remember, I think it was apps that use DirectX that have problems being hosted within a panel...   but other than that, it might be ok.

I'll see if i can work out how to do it (if another expert doesn't answer before hand)
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
steveo555Author Commented:
Thats great can I use the process object to detect when it closes?
0
 
S-TwilleyCommented:
yup... obviously edit this to include your hosting part... but:

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
        Dim p As New Process
        p.StartInfo.FileName = "C:\windows\notepad.exe"
        p.EnableRaisingEvents = True
        AddHandler p.Exited, AddressOf ProcessEnded
        p.Start()
    End Sub

    Sub ProcessEnded(ByVal sender As Object, ByVal e As EventArgs)
        Dim thisProcess As Process = DirectCast(sender, Process)
        MsgBox(thisProcess.StartInfo.FileName & " has exited")
    End Sub
0
 
steveo555Author Commented:
one final question.

Dim p As New Process
        p.StartInfo.FileName = "notepad.exe"
        p.StartInfo.CreateNoWindow = False
        p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
        p.EnableRaisingEvents = True
        AddHandler p.Exited, AddressOf ProcessEnded
        p.Start()
        p.WaitForInputIdle()
        SetParent(p.MainWindowHandle.ToInt32, Panel1.Handle.ToInt32)
        p.WaitForInputIdle()
        SendMessage(p.MainWindowHandle.ToInt32, WM_SYSCOMMAND, SC_MAXIMIZE,

why does this code not maximize the application in the panel? It does if I click maximise on notepad but not when I send the message to open.
0
 
S-TwilleyCommented:
try testing the API with an app that's not hosted in your application... i.e. remove the line with SetParent

see if that maximizes or not... then you'll know if the problem is because its hosted... or cos of your SendMessage
0
 
steveo555Author Commented:
Does the same thing, sendmessage isnt working is there any other way of forcing a maximize or minimize for a process?
0
 
S-TwilleyCommented:
could you post up the API and constants you are using for your maximize API call.
0
 
steveo555Author Commented:
Const WM_SYSCOMMAND As System.Int64 = &H112
    Const SC_MAXIMIZE As System.Int64 = &HF030

Private Declare Function SendMessage Lib "user32" Alias _
    "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Long, ByVal lParam As Object) As Long



SendMessage(p.Handle.ToInt32, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
0
 
S-TwilleyCommented:
VB.NET doesn't use Long's in APIs...

replace your API declaration with...

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

... and change your send message for.

SendMessage(p.MainWindowHandle.ToInt32, WM_SYSCOMMAND, SC_MAXIMIZE, 0)

you used p.Handle which is the handle of the process... and not handle of the window
0
 
steveo555Author Commented:
Your a star an I'm a muppet. Thanks for all your help and here are your points.
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now