在图片框中运行另一个应用程序 [英] Running another application inside a picturebox

查看:41
本文介绍了在图片框中运行另一个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我用来在图片框中运行另一个应用程序的示例代码:

This is the sample code that I used to run another application inside a picturebox:

Imports System.Diagnostics
Imports System.Runtime.InteropServices
Public Class Form1
    <DllImport("user32.dll")> Public Shared Function SetParent(ByVal hwndChild As IntPtr, ByVal hwndNewParent As IntPtr) As Integer
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim Process1 As New Process
        Process1.StartInfo.FileName = "notepad.exe"
        Process1.Start()

        Do Until Process1.WaitForInputIdle = True
            Application.DoEvents()
        Loop
        SetParent(Process1.MainWindowHandle, PictureBox1.Handle)

    End Sub
End Class

因此,我能够在我的 VB2010 WindowsForm 中托管另一个应用程序并且它运行良好.但问题是,在 Windows7 中,Windows 会要求权限(无论您是否允许 EXE 运行).单击允许"按钮后,exe 应用程序将在其自己的窗口中打开,而不是作为 PictureBox 的子项

Thus, I was able to host another application inside my VB2010 WindowsForm and it works fine. But the problem is, in Windows7, Windows would ask for the permission(whether you want to allow the EXE to run or not). After clicking the "Allow" button, the exe application would open on it's own window rather than as a child of the PictureBox

我认为当 Windows 请求许可时,它会跳过 SetParent() API 调用.我非常感谢任何建议.

I think when Windows asks for the permission, it is skipping the SetParent() API call. I really appreciate any suggestions.

谢谢:)

推荐答案

抱歉延迟发布解决方案.来自 VBForums.com 的 EdgeMeal 帮助我找到了解决此问题的方法.您可以在此处查看详细信息:vbforums.com 上的帖子

Sorry for the delay in posting the solution. EdgeMeal from VBForums.com had helped me in finding a workaround to this issue. You could view the details here: thread at vbforums.com

而为了提升权限,即在应用程序启动时请求Admin权限,我们需要更改requestedExecutionLevel值.要更改此设置,请转到项目属性(项目菜单 --> 属性).然后从 Application 选项卡中,单击 View Windows Settings 按钮.这将打开 app.manifest 文件.在此,更改以下行(未注释行):

And for elevating the permission, that is to ask for the Admin permission when the application starts, we need to change the requestedExecutionLevel value. To change this, goto the project properties(Project menu --> Properties). Then from the Application tab, click on the View Windows Settings button. This will open the app.manifest file. In this, change the following line(uncommented line):

<requestedExecutionLevel level="asInvoker" uiAccess="false" />

到:

<requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />

每当您运行应用程序时,这都会询问管理员权限.即使您从 IDE 运行它,它也会要求以管理员权限重新打开 IDE.

This will ask the Admin permission whenever you run the application. Even when you run it from IDE, it will ask for re-opening the IDE with the Admin privilege.

顺便说一句,我假设您将使用 VB2010.以上步骤是针对VB2010的(不知道其他版本是否也一样).

BTW, I assumed that you would be using VB2010. The above steps are for VB2010(not sure whether it would be same for other versions also).

希望对遇到同样问题的人有所帮助.:)

Hope it helps to someone who is fighting with the same issue. :)

这篇关于在图片框中运行另一个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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