Make your application stay on top

Posted On 2018-01-13 by VB6Boy
Tags: VB6 Windows API VB6 Miscellaneous Windows
Views: 75

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

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 the Author

VB6Boy has posted a total of 71 articles.

Comments On This Post

No comments on this post yet!

Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.

Your IP address is:

Before you can post, you need to prove you are human. If you log in, this test goes away.

Code Links