-
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.
-
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
-
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
-
Thanks guys. Paul, I didn't see the API at the site. Chris, the code you gave works great. Thanks again.
Wade