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 .NET
DescriptionThis example shows how to make a window stay below all others in Visual Basic .NET.
Keywordsbottommost, topmost, subclass, windowproc, setwindowlong, on bottom, Visual Basic .NET, VB.NET
CategoriesAPI, Tips and Tricks
 
This program's form overrides its WndProc subroutine. When it sees a WM_PAINT or WM_CAPTURECHANGED message, it uses the SetWindowPos API function to move the form to the bottom of the stacking order.
 
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function SetWindowPos(ByVal hWnd As IntPtr, _
    ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, _
    ByVal Y As Integer, ByVal cx As Integer, ByVal cy As _
    Integer, ByVal uFlags As UInt32) As Boolean
End Function

ReadOnly HWND_BOTTOM As New IntPtr(1)

Private Const SWP_NOSIZE As UInt32 = &H1
Private Const SWP_NOMOVE As UInt32 = &H2

Protected Overrides Sub WndProc(ByRef m As _
    System.Windows.Forms.Message)
    Const WM_PAINT = &HF
    Const WM_CAPTURECHANGED = &H215

    If (m.Msg = WM_PAINT) Or (m.Msg = WM_CAPTURECHANGED) _
        Then
        ' We're being activated. Move to bottom.
        Dim flags As UInt32 = SWP_NOMOVE Or SWP_NOSIZE
        SetWindowPos(Me.Handle, HWND_BOTTOM, 0, 0, 0, 0, _
            flags)
    End If

    ' Debug.WriteLine(m.ToString)

    MyBase.WndProc(m)
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated