Results 1 to 4 of 4

Thread: Keeping a shelled app window on top

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    Kingswood, UK
    Posts
    6
    I know how to keep a window on top if it is in the same app
    as the code (using API calls), and I know how to shell to
    an app, but I don't know how to keep a window from an app
    that isn't the the one with the code in on top.

    Any ideas, anyone?

  2. #2
    Guest
    Use the SetWindowPos api function, same as with making your own form on top.

    Code:
    'Tip by Sam Huggill
    
    Private Declare Function SetWindowPos Lib "user32" (ByVal _
    hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As _
    Long, y, ByVal cx As Long, ByVal cy As Long, ByVal wFlags _
    As Long) As Long
    
    Private Const HWND_TOPMOST = -1
    Private Const HWND_NOTOPMOST = -2
    Private Const SWP_NOMOVE = &H2
    Private Const SWP_NOSIZE = &H1
    Private Const SWP_NOACTIVATE = &H10
    Private Const SWP_SHOWWINDOW = &H40
    Private Const TOPMOST_FLAGS = SWP_NOMOVE Or SWP_NOSIZE
    
    'Resets the windows position in the ZOrder
    Private Sub MakeNormal(lngHwnd As Long)
        SetWindowPos lngHwnd, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
    End Sub
    
    'Places the window at the top of the ZOrder
    'and keeps it there
    Private Sub MakeTopMost(lngHwnd As Long)
        SetWindowPos lngHwnd, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
    End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    Kingswood, UK
    Posts
    6
    I _know_ how to use SetWindowPos, I don't know how to get the hWnd for a window that is not part of the program.

  4. #4
    Guest
    Use the FindWindow api function.

    Code:
    Private Declare Function FindWindow Lib "user32" _
    Alias "FindWindowA" (ByVal lpClassName As String, ByVal _
    lpWindowName As String) As Long
    
    Private Sub Command1_Click()
    'hWin = FindWindow(Class, Caption)
    hWin = FindWindow("SciCalc", "Calculator")
    If hWin <> 0 Then Msgbox "hWnd: " & hWin
    End Sub

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