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

时间:2018-03-21 09:14:21

标签: .net vb.net always-on-top

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

但是,当用户在presentatoin全屏模式下使用PowerPoint并且我的应用程序试图将其置于最顶层时,它无法执行此操作。

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

我如何告诉我的应用程序即使有像全屏模式应用程序运行的任何功能点也将我的应用程序放在首位。因为它紧急来电弹出。

1 个答案:

答案 0 :(得分:1)

如果你寻找"总是排在最前面"你找不到完美的解决方案。

另一种解决方案可能是隐藏所有窗口(甚至PP全屏演示模式),如WinKey + D,并在来电时恢复您的应用程序呼叫中心窗口(或显示通知图标)。

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。

enter image description here

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