当特定程序“.exe”打开时显示消息框

Show message box when a specifc program ".exe" open

我正在玩一款需要大约 30 秒才能加载和打开的游戏,所以我决定为其创建一个请稍候的应用程序 该应用程序的想法是: 用户点击它然后我的应用程序将打开游戏并说请等待标签将出现然后 我的应用程序将自行关闭

问题是我不知道如何让我的应用程序显示 "Welcome to XXX " 然后在 "DMC.exe" 打开

时关闭

谢谢^^

这取决于 "DMC.exe" 的写法,但最简单的解决方案是尝试使用 Process.WaitForInputIdle():

Causes the Process component to wait indefinitely for the associated process to enter an idle state.

一旦显示主要 window 并等待用户输入,通常会到达 "idle state":

Public Class Form1

    Private P As Process
    Private T As System.Threading.Thread

    Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
        P = Process.Start("dmc.exe")
        T = New System.Threading.Thread(AddressOf Wait)
        T.Start()
    End Sub

    Private Sub Wait()
        P.WaitForInputIdle()
        Application.Exit()
    End Sub

End Class

根据 .exe 时间加载大约 30 秒然后

  1. 创建一个名为 "loadingform"(或任何)的表格。
  2. 将您的计时器添加到 "loadingform"
  3. 将此代码输入您的计时器
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Me.Hide() '   "Me" your loadingform 
          Timer1.Dispose()
          'Do anything after your loadingform hide
        End Sub
  1. 将 "timer1" 属性更改为:
    • 启用 = 真
    • 间隔 = 30000