Results 1 to 4 of 4

Thread: Window on Top?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363
    Hi, how can I tell if a window is in the foreground (on top) but not the active window? It wouldn't be covered by any other windows but it doesn't take up the entire screen so another window could be the active one. I just need to know if it can be seen.

    Thanks for any help.
    Wade

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    I've seen an API which returns the visible region of a window, I think Kedamans site had it (Class explorer screenshot)


    http://www.geocities.com/kedasu/kedacode.html
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Wink

    Hope this is what you looking for...

    Code:
    Option Explicit
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As String) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    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
    
    Private Const SW_SHOWNORMAL = 1
    Private Const HWND_TOPMOST = -1
    Private Const HWND_NOTOPMOST = -2
    Private Const HWND_TOP = 0
    Private Const SWP_NOSIZE = &H1
    Private Const SWP_NOMOVE = &H2
    Private Sub Command1_Click()
    Dim xhwnd&, dl&
    If Len(Text1) = 0 Then Exit Sub
        xhwnd = FindWindow(0&, Text1.Text)
        If xhwnd <> 0 Then
            If Check1.Value Then
                dl = ShowWindow(xhwnd, SW_SHOWNORMAL)
                dl = SetWindowPos(xhwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
            ElseIf Check2.Value Then
                dl = ShowWindow(xhwnd, SW_SHOWNORMAL)
                dl = SetWindowPos(xhwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
            ElseIf Check3.Value Then
                dl = ShowWindow(xhwnd, SW_SHOWNORMAL)
                dl = SetWindowPos(xhwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
            End If
        End If
    End Sub
    Private Sub Form_Load()
    Label1.Caption = "Please type the target window name."
    End Sub
    
    Private Sub Text1_Change()
    end Sub

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363
    Thanks guys. Paul, I didn't see the API at the site. Chris, the code you gave works great. Thanks again.

    Wade
    Wade

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