使应用程序位于所有其他应用程序之上

Making the application on top of all other applications

我有 VB 代码如下,在呼叫中心用于接听或拒绝紧急来电。它正在努力将我的应用程序置于所有其他应用程序之上的基本用法。

但是,当用户在全屏模式下使用 PowerPoint 时,我的应用程序试图将其置于最上面,但它失败了。

  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.TopMost = True
  end sub 

我如何告诉我的应用程序,即使有任何电源点,如全屏模式应用程序 运行 将我的应用程序放在最上面。因为它的紧急来电弹窗。

如果您寻找 "always on top",您将找不到完美的解决方案。

另一种解决方案是隐藏所有 windows(甚至 PP 全屏演示模式),例如 WinKey+D 并恢复您的应用程序 call-center window(或显示通知图标)来电。

using System.Threading;
using System;

namespace callCenterApp
{
  internal class Program
  {
    [STAThread]
    private static void Main(string[] args)
    {
      showDesktop();
    }

    private static void showDesktop()
    {
      Shell32.ShellClass objShel = new Shell32.ShellClass();
      objShel.ToggleDesktop();

      Thread.Sleep(1000);

      var notification = new System.Windows.Forms.NotifyIcon()
      {
        Visible = true,
        Icon = System.Drawing.SystemIcons.Warning,
        BalloonTipText = "Incomming emergency call",
        BalloonTipTitle = "Alert!",
        BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Warning
      };
      notification.ShowBalloonTip(5000);
      Thread.Sleep(10000);
      notification.Dispose();
    }
  }
}

导入 Microsoft Shell 控制和自动化 COM (windows/SysWoW64/shell32.dll) 以与 shell.

一起使用

VB.NET版本:

Namespace callCenterApp
    Friend Class Program
        <STAThread> _
        Private Shared Sub Main(args As String())
            showDesktop()
        End Sub

        Private Shared Sub showDesktop()
            Dim objShel As New Shell32.ShellClass()
            objShel.ToggleDesktop()

            Thread.Sleep(1000)

            Dim notification As New System.Windows.Forms.NotifyIcon() With { _
                .Visible = True, _
                .Icon = System.Drawing.SystemIcons.Warning, _
                .BalloonTipText = "Incomming emergency call", _
                .BalloonTipTitle = "Alert!", _
                .BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Warning _
            }
            notification.ShowBalloonTip(5000)
            Thread.Sleep(10000)
            notification.Dispose()
        End Sub
    End Class
End Namespace