Results 1 to 10 of 10

Thread: How to find out if a form is 'on-top'?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2014
    Posts
    84

    How to find out if a form is 'on-top'?

    Google returns countless articles/examples of how to set a form topmost or not_topmost using the SetWindowPos API. But, how do I determine if a Window has been set topmost? TIA. Bob.

  2. #2
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,009

    Re: How to find out if a form is 'on-top'?

    Code:
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongW" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    Private Const GWL_EXSTYLE As Long = (-20)
    Private Const WS_EX_TOPMOST As Long = &H8&
    
    Private Function IsWindowTopMost(hWnd As Long) As Boolean
        IsWindowTopMost = (GetWindowLong(hWnd, GWL_EXSTYLE) And WS_EX_TOPMOST) <> 0
    End Function

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2014
    Posts
    84

    Resolved Re: How to find out if a form is 'on-top'?

    Excellent. Many thanks.

  4. #4
    Hyperactive Member
    Join Date
    Mar 2017
    Posts
    500

    Re: How to find out if a form is 'on-top'?

    I have a question about top-most. Is it possible to change a window's top-most state from top-most to not top-most and back again while it's running

  5. #5
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: How to find out if a form is 'on-top'?

    Quote Originally Posted by Ordinary Guy View Post
    I have a question about top-most. Is it possible to change a window's top-most state from top-most to not top-most and back again while it's running
    Didn't you say the examples showed you that in your first post, i.e. set the form to not_topmost.
    Quote Originally Posted by K4CY View Post
    Google returns countless articles/examples of how to set a form topmost or not_topmost using the SetWindowPos API. ....
    Of course the form will still be on top if it is already on top. It just won't stay on top if you click on another window that overlaps the area it is in.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  6. #6
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: How to find out if a form is 'on-top'?

    Quote Originally Posted by passel View Post
    Didn't you say the examples showed you that in your first post, i.e. set the form to not_topmost.
    Except Ordinary Guy isn't K4CY unless you know something we don't.

  7. #7
    Hyperactive Member
    Join Date
    Mar 2017
    Posts
    500

    Re: How to find out if a form is 'on-top'?

    Quote Originally Posted by passel View Post
    Didn't you say the examples showed you that in your first post, i.e. set the form to not_topmost.

    Of course the form will still be on top if it is already on top. It just won't stay on top if you click on another window that overlaps the area it is in.
    Not sure that is correct. If I have an app running top-most and I click on another app the top-most app will still be top-most otherwise it defeats the purpose of top-most

  8. #8
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: How to find out if a form is 'on-top'?

    OptionBase1, , didn't notice the interloper.

    Ordinary Guy, you asked if the windows topmost state could be changed.
    I was saying that it could.

    Quote Originally Posted by Ordinary Guy View Post
    Not sure that is correct. If I have an app running top-most and I click on another app the top-most app will still be top-most otherwise it defeats the purpose of top-most
    I was saying if you set the app to no longer be top-most (which sounded like what you were asking), then it will not remain top-most. It won't automatically dive under other windows when you remove the top-most attribute, i.e. it will still be on top of other windows, until an overlapping window is selected.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

  9. #9
    Hyperactive Member
    Join Date
    Mar 2017
    Posts
    500

    Re: How to find out if a form is 'on-top'?

    Here's my question rephrased. I have two apps. App2 is top-most. Now, at some point in time while both apps are running I want to make App1 top-most so it sits on top of App2. Later I want to make App1 not top-most thus allowing App2 to become top-most again so it sits on top of App1. I only have the exe of App2 but App1 is my app so I have total control over it. Is this possible?

  10. #10
    Hyperactive Member
    Join Date
    Mar 2017
    Posts
    500

    Re: How to find out if a form is 'on-top'?

    OK, never mind, I got it to work like I want it

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