Results 1 to 4 of 4

Thread: Always on top

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    -
    Posts
    101
    How can you make an application/form always on top?

    I'm using VB 6.0 Enterprise Ed.
    icq: 16228887

  2. #2
    New Member
    Join Date
    Jul 2000
    Location
    São Paulo/Brazil
    Posts
    13
    Code on the form:

    Option Explicit

    Private Sub Command1_Click()
    Dim lR As Long
    lR = SetTopMostWindow(Form1.hwnd, True)
    End Sub

    Private Sub Command2_Click()
    Dim lR As Long
    lR = SetTopMostWindow(Form1.hwnd, False)
    End Sub

    Code on a module:

    Option Explicit
    Public Const SWP_NOMOVE = 2
    Public Const SWP_NOSIZE = 1
    Public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
    Public Const HWND_TOPMOST = -1
    Public Const HWND_NOTOPMOST = -2

    Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" _
    (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

    Public Function SetTopMostWindow(hwnd As Long, Topmost As Boolean) _
    As Long

    If Topmost = True Then 'Make the window topmost
    SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, _
    0, FLAGS)
    Else
    SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, _
    0, 0,FLAGS)
    SetTopMostWindow = False
    End If
    End Function


  3. #3
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    This has always worked for me.

    Code:
    #If Win32 Then
    
    
    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
    #Else 'Win16
    
    
    Private Declare Sub SetWindowPos Lib "User" (ByVal hWnd As Integer, _
        ByVal hWndInsertAfter As Integer, ByVal X As Integer, _
        ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, _
        ByVal wFlags As Integer)
    #End If
    Const SWP_NOMOVE = 2
    Const SWP_NOSIZE = 1
    Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
    Const HWND_TOPMOST = -1
    Const HWND_NOTOPMOST = -2
    
    
    Private Sub Form_load()
    #If Win32 Then
        Dim lResult As Long
        lResult = SetWindowPos(Me.hWnd, HWND_TOPMOST, _
        0, 0, 0, 0, FLAGS)
    #Else '16-bit API uses a Sub, Not a Function
        SetWindowPos Me.hWnd, HWND_TOPMOST, _
        0, 0, 0, 0, FLAGS
    #End If
    
    end sub

    Hope this helps

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    -
    Posts
    101
    thanks guys! that was fast.
    icq: 16228887

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width