Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake a window stay below all others in Visual Basic 6
DescriptionThis example shows how to make a window stay below all others in Visual Basic 6.
Keywordsbottommost, topmost, subclass, windowproc, setwindowlong, on bottom, Visual Basic 6, VB 6
CategoriesAPI, Tips and Tricks
 
When it starts, the program subclasses its form. The following code shows the new WindowProc.

When it sees a WM_ACTIVATE or WM_PAINT message, it uses the SetWindowPos API function to move the form to the bottom of the stacking order.

 
' Handle messages.
Public Function NewWindowProc(ByVal hwnd As Long, ByVal msg _
    As Long, ByVal wParam As Long, ByVal lParam As Long) As _
    Long
Const WM_ACTIVATE = &H6
Const WM_PAINT = &HF
Const WM_NCDESTROY = &H82
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1
Const HWND_BOTTOM = 1

Dim lFlags As Long

    If (msg = WM_ACTIVATE) Or (msg = WM_PAINT) Then
        ' We're being activated. Move to bottom.
        lFlags = SWP_NOSIZE Or SWP_NOMOVE
        SetWindowPos hwnd, HWND_BOTTOM, _
            0, 0, 0, 0, lFlags
    ElseIf msg = WM_NCDESTROY Then
        ' We're being destroyed.
        ' Restore the original WindowProc.
        SetWindowLong _
            hwnd, GWL_WNDPROC, _
            OldWindowProc
    End If

    NewWindowProc = CallWindowProc( _
        OldWindowProc, hwnd, msg, wParam, _
        lParam)
End Function
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated