VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Keep a form on top

by Dennis Wrenn (2 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

This code keeps a form on top of all other windows.

API Declarations
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
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_FLAGS = SWP_NOMOVE Or SWP_NOSIZE

Rate Keep a form on top

'code:
Private Sub FormOnTop(frm As Form, blnOnTop As Boolean)
  Dim lPos As Long
  Select Case blnOnTop
    Case True
      lPos = HWND_TOPMOST
    Case False
      lPos = HWND_NOTOPMOST
  End Select
  Call SetWindowPos(frm.hwnd, lPos, 0, 0, 0, 0, SWP_FLAGS)
End Sub
'usage:
Private Sub Form_Load()
'makes a form on top
  Call FormOnTop(Me, True)
End Sub
Private Sub Command1_Click()
'makes a form not always on top anymore..
  Call FormOnTop(Me, False)
End Sub

Download this snippet    Add to My Saved Code

Keep a form on top Comments

No comments have been posted about Keep a form on top. Why not be the first to post a comment about Keep a form on top.

Post your comment

Subject:
Message:
0/1000 characters