Is window visible, in front

Ocrana used Ask the Experts™

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).

Watch Question

Do more with

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

Win32 API. IsWindowVisible

if (IsWindowVisible(hWnd))

This function allows to check if a window is visible.

in MFC CWnd class has a method with the same name:

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.

There is also GetNextWindow function that gives next and previous windows in the z-order

Also there is GetWindowRect if you need to detect the window rectangle.
Freelance programmer / Consultant
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


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