VB Notebook Main Page VB Notebook Files VB Notebook Function Library VB Notebook Articles VB Notebook Links VB Notebook

VBNotebook Home | Functions | Form On Top

This routine toggles stay-on-top status for a specified form. If bToggle is True then the form is on-top, if it is False, the form is not on top.

In General|Declarations, you'll need the following API declaration and constants....
__________________________________________________________________________________________

'
' Window Position Constants
'

Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Const SWP_FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
'
' API Calls
'
Private Declare Function 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) As Long

__________________________________________________________________________________________

The toggle routine looks like this...
__________________________________________________________________________________________

Public Sub OnTop(FRM As Form, ByVal bToggle As Boolean)
    Dim nRet As Long

    Select Case bToggle
        Case True
            nRet = SetWindowPos(FRM.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_FLAGS)
        Case False
            nRet = SetWindowPos(FRM.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_FLAGS)
        End Select

End Sub

__________________________________________________________________________________________

Copyright 2000-2005, J. Frank Carr