Search Tools Links Login

Make your application stay on top


Keep your application on top of all other applications. Comes in handy if you're writing a "toolbar" type of application.

Place the following code in a module. This is the reference and configuration for the system API that we are going to use to make our window topmost.

Private Declare Function SetWindowpos Lib "user32" ( _
    ByVal hWnd As long, _
    ByVal hWndInsertafter as long, _
    ByVal x as long, _
    ByVal y As long, _
    ByVal y As long, _
    ByVal wFlag As long _
) As long
Const HWND_TOPMOST = -1
Const SWP_SHOWWINDOW = &H40

Simply placing the above code in a module will not make the magic happen. When your main form instantiates or loads, you want to make a call to the above defined API. This will bring your window to the top, and leave it there.

Private Sub Form_Load()
    dim retVal As long
    retVal = SetWindowPos(Me.hWnd, HWND_TOPMOST, Me.CurrentX, me.CurrentY, 300, 300, SWP_SHOWWINDOW)
End sub

About this post

Posted: 2018-01-13
By: vb6boy
Viewed: 399 times

Categories

Windows

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.