【问题标题】:Can I have notify icon for my external program called by shell?我可以为 shell 调用的外部程序设置通知图标吗?
【发布时间】:2023-03-23 22:31:01
【问题描述】:

我正在开发一个 exe 程序 (A),它具有调用另一个 exe(B) 的链接。但是,我在为 exe (B) 设置通知图标时遇到了问题。

这里调用exe(B)的代码:

Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked

    Shell("C:\\programB.exe", AppWinStyle.NormalFocus)

End Sub

如何将通知图标放到 exe(B) 中?

【问题讨论】:

    标签: vb.net exe notifyicon multiple-projects


    【解决方案1】:

    您不能在运行时修改应用程序。但是,您可以保持应用程序B的进程,然后您可以在任务栏中显示通知图标,直到应用程序运行为止。

    Dim bHasNotifyIcon As Boolean = False
    Dim process As Diagnostics.Process = Diagnostics.Process.Start("D:\ProgrammB.exe")
    
    If Not process.HasExited Then 
        bHasNotifyIcon = True
        'Show Notify Icon
    End If
    
    Do While (Not process.HasExited)
        'Do nothing
    Loop
    
    'Hide Notify icon if application is running
    If bHasNotifyIcon Then 
        'Hide Notify Icon
    End If
    

    注意:不要忘记在不同的线程中运行上面的代码,否则它会挂起应用程序。当您尝试从不同的线程访问 UI 时,它可能会出错。

    是的,我知道这是最肮脏的方法。但是,我不知道任何其他方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-21
      • 2015-07-08
      • 1970-01-01
      • 2010-09-22
      相关资源
      最近更新 更多