Keep Form on Top

The following code will keep your form on top of other application forms and any other windows program.

It does not prevent the user from using ALT+TAB or the windows keyboard key, but is a good way to make sure the user will see your window.

On top of your form put the code below

Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40

Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, _
            ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, _
            ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)

Now, let's tell the form to keep itself on top of everything

Private Sub Form_Load()
    SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, _
                SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License