Results 1 to 7 of 7

Thread: Keeping a Window on top (not a form)

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2002
    Posts
    34

    Keeping a Window on top (not a form)

    Hello,
    I'm trying to keep the 'open with' dialog on top until you select a program or cancel. Or bring it back to the top if you right click on the listbox. I've posted my code, could somebody tell me what I'm doing wrong. The only examples i've seen for BringWindowToTop API are 'BringWindowToTop form2.hwnd'. How can I apply that to the 'open with' dialog box??

    '=========================
    Private Sub lstLoad_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single)
    'Bring up the 'open with' dialog and open selected file
    '=========================

    Dim WinWnd As Long
    Dim zhWnd as Long
    If lstLoad.ListIndex <> -1 Then
    WinWnd = FindWindow(vbNullString, "Open With") 'if the openwith dialog is already open
    If WinWnd = 0 Then
    Call GetListItemInfo(lstLoad)
    If Button = vbRightButton Then
    Shell ("rundll32.exe shell32.dll,OpenAs_RunDLL " & strFullName)
    zhWnd = GetActiveWindow
    End If
    Else
    BringWindowToTop(zHwnd)
    End If

    End If

    End Sub

    Thank you,
    Rick

  2. #2
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    VB Code:
    1. Private Sub lstLoad_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    2. 'Bring up the 'open with' dialog and open selected file
    3. '=========================
    4.  
    5. Dim WinWnd As Long
    6. Dim zhWnd As Long
    7. If lstLoad.ListIndex <> -1 Then
    8. zhWnd = FindWindow(vbNullString, "Open With") 'if the openwith dialog is already open
    9. If zhWnd = 0 Then
    10. Call GetListItemInfo(lstLoad)
    11. If Button = vbRightButton Then
    12. Shell ("rundll32.exe shell32.dll,OpenAs_RunDLL " & strFullName)
    13. zhWnd = GetActiveWindow
    14. End If
    15. Else
    16. SetWindowPos zhWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
    17.  
    18. End If
    19.  
    20. End If
    21.  
    22. End Sub

    Tell me if it did!!!

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2002
    Posts
    34
    moinkhan,

    Beautiful!, Thanks a bunch!

  4. #4
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    I thought GetActiveWindow only worked for windows that you owned? If this doesn't work, then just change it to "GetForegroundWindow"

  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2002
    Posts
    34
    Hi Megatron,
    I tried your suggestion with the GetForegroundWindow, the result from that and GetActiveWindow is the same. Would there be any reason to use one over the other?
    Thanks for the reply,
    Rick

  6. #6
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    GetActiveWindow returns the Active window of the Calling thread..
    While GetForeGroundWindow returns the Foreground window which currently is on top of all the windows.. of all the applicaitons..

  7. #7
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    Originally posted by rruble88
    Hi Megatron,
    I tried your suggestion with the GetForegroundWindow, the result from that and GetActiveWindow is the same.
    Rick
    What is the the result? Flashing of the titlebar?

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