vb.net 在表单内启动应用程序 [英] vb.net Launch application inside a form

查看:63
本文介绍了vb.net 在表单内启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在面板内或我的应用程序中运行某个应用程序.这是一个模拟器前端.您浏览游戏,然后当您选择一个时,它会启动模拟器.我找到了以下代码并将其改编为我的项目

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

如果我用记事本或什至 zsnesw.exe 尝试它,它工作正常,但是如果我尝试将一些参数传递给 zsnesw 它有点吓人,我必须重新启动我的计算机(我无法切换应用程序,甚至打开任务管理器).

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.

推荐答案

我成功了!

        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()

问题 1: 我错误地传递了参数.我试图使用 Process.StartInfo.Arguments.由于某种原因没有工作.在 Process.Start 中使用逗号可以正常工作.

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.

问题 2: 我添加了 Me.BringToFront() 以再次隐藏开始菜单.

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

这篇关于vb.net 在表单内启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆