Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vb.net Launch application inside a form

I want to run an app inside a panel or something within my applicaiton. It's an emulator front end. You browse through games, then when you select one it launches the emulator. I found the following code and adapted it to my project

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)
    End Sub
End Class

If I try it with notepad, or even zsnesw.exe it works okay, but if I try to pass some parameters to zsnesw it kind of freaks out and I have to reboot my computer (I can't switch applications or even open the task manager).

Also, even when it does work, the start menu pops up like I have switched to another app. This is kind of what I was trying to avoid in the first place as my app is full screen.

like image 466
THE JOATMON Avatar asked Nov 30 '12 19:11

THE JOATMON


People also ask

How do I open an app in Visual Studio?

If your program code is already in a Visual Studio project, open the project. To do so, you can double-click or tap on the . csproj file in Windows File Explorer, or choose Open a project in Visual Studio, browse to find the . csproj file, and select the file.

What is Vbnet application?

Visual Basic, originally called Visual Basic . NET (VB.NET), is a multi-paradigm, object-oriented programming language, implemented on . NET, Mono, and the . NET Framework. Microsoft launched VB.NET in 2002 as the successor to its original Visual Basic language, the last version of which was Visual Basic 6.0.


1 Answers

I got it working!

        Dim proc As Process
        proc = Process.Start(emuPath + "zsnesw", "-m """ + selGame.romPath + """")
        proc.WaitForInputIdle()
        SetParent(proc.MainWindowHandle, Me.Panel1.Handle)
        SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
        Me.BringToFront()

Problem 1: I was passing the arguments incorrectly. I was trying to use Process.StartInfo.Arguments. Didn't work for some reason. Using a comma in Process.Start works fine.

Problem 2: I added Me.BringToFront() to hide the start menu again.

like image 149
THE JOATMON Avatar answered Sep 24 '22 06:09

THE JOATMON