.netvb.netalways-on-top

Making the application on top of all other applications


I have VB code as below which is used in call-center for emergency incoming calls to answer or reject. Which is working to put my application on top of all other application in a basic usage.

But, when user using PowerPoint in presentatoin full-screen mode and my application is trying to go on top it, it fails to do so.

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

How do i tell my application even there is any power-point like fullscreen mode applications running put my application on top. Because its emergency incoming call popup.


Solution

  • If you look for "always on top" you will not find a flawless solution.

    An alternative solution could be hidde all windows (even PP fullscreen presentation mode) like WinKey+D and restore your app call-center window (or show a notify icon) on incoming call.

    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();
        }
      }
    }
    

    Import Microsoft Shell Controls And Automation COM (windows/SysWoW64/shell32.dll) to work with shell.

    enter image description here

    VB.NET version:

    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