Search Tools Links Login

Keep a form on top!


Visual Basic 6, or VB Classic

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

Original Author: Dennis Wrenn

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

Code

'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

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 88 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.