Results 1 to 18 of 18

Thread: Always on top - with a twist

  1. #1
    anoop007
    Guest
    How do I reset the "Always on top" property of a window owned by an external application.?.. Maybe finding the hwnd of the window may do the trick.. but how?

  2. #2
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    you could use the SetWindowPos API with the HWND_NOTOPMOST constant:

    Code:
    Option Explicit
          ' SetWindowPos Function
          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
          ' SetWindowPos Flags
          Private Const SWP_NOSIZE = &H1
          Private Const SWP_NOMOVE = &H2
          Private Const HWND_TOPMOST = -1
          Private Const HWND_NOTOPMOST = -2
    
    Private Sub Command1_Click()
            'replace Me.hWnd with the hWnd of the window you want to move here
            'NB you may encounter problems with dialog boxes, or other windows that REALLY don't want to move
            'from the top
             Call SetWindowPos(Me.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, _
                               SWP_NOSIZE Or SWP_NOMOVE)
             Unload Me
    End Sub
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  3. #3
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Code:
    Dim h as Long
    h = FindWindow("classname","titlebartext");
    
    SetWindowPos h, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_FRAMECHANGED Or SWP_NOMOVE
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  4. #4
    anoop007
    Guest
    unfortunately the window does not have a titlebar

    what is classname ?

  5. #5
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Use the Spy++ utility to find the class name.

  6. #6
    Lively Member
    Join Date
    Mar 2001
    Posts
    82

    Exclamation Question not an answer



    Instead of wanting to take away the Always on Top property, is it possible to make a Form 'always on top', something like the tool boxes in Adobe Photoshop.

    Thank You.

  7. #7
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Code:
    Const HWND_BOTTOM = 1
    Const HWND_NOTOPMOST = -2
    Const HWND_TOP = 0
    Const HWND_TOPMOST = -1
    Const SWP_NOMOVE = &H2
    Const SWP_NOSIZE = &H1
    
    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
    
    Sub MakeWindowAlwaysTop(hwnd As Long)
        SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
    End Sub
    
    Sub MakeWindowNotTop(hwnd As Long)
        SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
    End Sub
    
    
    Private Sub Form_Load()
      MakeWindowAlwaysTop Me.hwnd
    End Sub

  8. #8
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Originally posted by anoop007
    unfortunately the window does not have a titlebar

    what is classname ?
    If you don't know the class name, you can always use null as the parameter

  9. #9
    Megatron
    Guest
    don't you mean NullString? (constant is vbNullString)

  10. #10
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Yes, I did mean NullString. Btw, can I pass 0& instead of vbNullString?

  11. #11
    Lively Member
    Join Date
    Mar 2001
    Posts
    82


    thanks Lethal. great help

    a follow up question is, what is the best way to control this form that is always on top so as when my main form (an MDI Form) is not in focus, let's say minimized or a new application is in use, this AlwaysOnTop Form would no longer be always on top?

    thanks again


  12. #12
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Well, just whenever u would not want the form to be set as always on top, in your code, call the MakeWindowNotTop Procedure and Vice Versa.

  13. #13
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    You can try that even, but I am not sure it will work.
    You can do one thing. Search in the forums for the code to know all displayed windows on the desktop. Once you know all the handles, you can get the caption of each window. This way, I think you can get to know the handle of the ad bar.
    Spy ++ is a utility provided with the enterprise edition of Visual Studio. You may even search msdn web site msdn.microsoft.com for the program. They might be giving out for free.

  14. #14
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    If you want to get rid of an address bar just delete the GUID from the registry....(it's not nice I know, but thats the way I did it)
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  15. #15
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    What he is talking about is not the address bar, but a advertising window bar which remains on top all the time.
    BTW, anoop007, If you d find the code for getting the handles to all the displayed window, do post a link here.

  16. #16
    Addicted Member Xdream's Avatar
    Join Date
    Mar 2001
    Location
    Switzerland
    Posts
    194
    Hi

    I downloaded a spy program from http://www.planetsourcecode.com/ and it's excellent. It's drag'n drop with treeview and it can even generate the code for topmostwindow, parentwindow and currentwindow.

    Regards, Xdream
    Attached Files Attached Files

  17. #17
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    you can pass a zero two ways: Vbnull or 0&

    to have your form on top only when it has focus, that will be taken care of when it's minimized so you dont have to worry about that. When it loses focus, give it normal z-order. When it gains focus, set it on top again.

    BTW the 4 zeros are the x and y top and the width and height of the form. You can use this function to set your window size.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  18. #18
    anoop007
    Guest
    That spy utility was cool..

    it served the purpose...

    thanks

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