IsWindowVisible API Catch
By Akbar • December 25th, 2007
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 (http://msdn2.microsoft.com/en-us/library/ms633530(VS.85).aspx), 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.”
This entry was posted
on Tuesday, December 25th, 2007 at 10:51 pm and is filed under Win32 API, Windows.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
Feedback & Comments
No Responses