IsWindowVisible API Catch

By Akbar
In one of my utilities, I was using the IsWindowVisible  function to get the current window state. Though it seems to be working at start, I found that it randomly fails and when debugging the issue, the IsWindowVisible was not returning the correct state i.e. a non-zero value even if the window was not visible. This was really weird as it’s a heavily used Windows API and if something was wrong with it, it must have been pointed out.

On carefully reading the MSDN documentation (, I found that there is catch in this function working which is not directly visible from the documentation. Check this from MSDN notes:
If the specified window, its parent window, its parent’s parent window, and so forth, have the WS_VISIBLE style, the return value is nonzero. Otherwise, the return value is zero.
So the catch is that it’s not exactly works as the function name mention it. All I have to do is create a new function, which just checks the WS_VISIBLE attribute and viola, it works.

Moral of the story is “Don’ rely on function names, always read the documentation first.”

Tags: , ,