Use:
SetWindowPos is used to keep a particular
"on-top" of all other windows. Unlike a form that is
loaded modal, using SetWindowPos the user can access other forms,
while having another form remain on-top. This is useful for "Splash"
screens where you want to have other forms loading, but still
have the splash screen remain on top. Or for "helper"
screens, such as a search-and-replace dialog which allows a user
to modify the document without closing the search-and-replace
dialog.
Declaring the function:
'declare the SetWindowPos function, used to keep the splash form on-top
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)
'declare constants used by SetWindowPos
Global Const HWND_TOPMOST = -1
Global Const HWND_NOTOPMOST = -2
Global Const SWP_NOACTIVATE = &H10
Global Const SWP_SHOWWINDOW = &H40
Calling the function:
'Call SetWindowPos to keep frmSplash "on-top"
SetWindowPos frmSplash.hWnd, HWND_TOPMOST, frmSplash.Left / 15, _
frmSplash.Top / 15, frmSplash.Width / 15, _
frmSplash.Height / 15, SWP_NOACTIVATE Or SWP_SHOWWINDOW
'Call SetWindowPos to undo the "on-top"-ness of frmSplash
SetWindowPos frmSplash.hWnd, HWND_NOTOPMOST, frmSplash.Left / 15, _
frmSplash.Top / 15, frmSplash.Width / 15, _
frmSplash.Height / 15, SWP_NOACTIVATE Or SWP_SHOWWINDOW