We help IT Professionals succeed at work.

bring project to on top off other application running

b001
b001 asked
on
Hi Experts
I have a small reminder type project and it is run by task scheduler at 9.00 am every day.
How can I make sure that it comes on top of already running applications?

Thanks
Comment
Watch Question

Most Valuable Expert 2011
Top Expert 2015
Commented:
Use the API function SetForegroundWindow:

Imports System.Runtime.InteropServices
...
<DllImport("user32.dll")> _
Private Shared Function SetForegroundWindow(ByVal hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function

Open in new window


You would then call it and pass it the handle to your application window. Something like this:

Public Class Form1

    <System.Runtime.InteropServices.DllImport("user32.dll")> _
    Private Shared Function SetForegroundWindow(ByVal hWnd As IntPtr) _
        As <System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
    End Function


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SetForegroundWindow(Me.Handle)
    End Sub
End Class

Open in new window