Is window visible, in front

Ocrana
Ocrana used Ask the Experts™
on
Hello,

howi t is possible to check whether a window has hwnd and is "visible" but not in Front/onTop?
I need to know when the window will lost TopPosition but is still visible (not minimized).

Ocrana
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Win32 API. IsWindowVisible
http://msdn.microsoft.com/en-us/library/ms633530(VS.85).aspx

if (IsWindowVisible(hWnd))
{  
   //something
}

This function allows to check if a window is visible.

in MFC CWnd class has a method with the same name:
http://msdn.microsoft.com/en-us/library/ms633530(VS.85).aspx

CWnd has also GetTopWindow (same name in Win API). If I understand you question correctly, you need this function.
This function gives the top window. Compare the result from this function with your window and it is not the same, you window is not the top window.

Commented:
There is also GetNextWindow function that gives next and previous windows in the z-order
http://msdn.microsoft.com/en-us/library/ms633509(VS.85).aspx

Also there is GetWindowRect if you need to detect the window rectangle.
Freelance programmer / Consultant
Commented:
CWnd* pWnd;
assign a window to pWnd (new, Create, Attach, GetDlgItem....)
.....


pWnd->GetSafeHwnd();    //returns NULL if no hwnd

(pWnd->GetSafeHwnd() != CWnd::GetForegroundWindow()->GetSafeHwnd())   //true if the foreground (active) window is a different window

pWnd->IsIconic();   returns true if minimised

Author

Commented:
Very good information,

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial