Today, let’s talk about a brain teaser. Check the two lines of code below to see what your first feeling is? ShowWindow(hwnd, SW_SHOWNORMAL);assert(IsWindowVisible(hwnd));We display a window through the first line of code. At this time, according to common sense, this window must

Today, let’s talk about a brain teaser.
examines the following two lines of code to see what your first feeling is?

ShowWindow(hwnd, SW_SHOWNORMAL);
assert(IsWindowVisible(hwnd));

We display a window through the first line of code. At this time, according to common sense, this window must be visible, right?
However, the assertion on the second line may be triggered (even in scenarios where multithreaded is not available). Why

?

The answer is as follows.
Please first look at the description of MSDN for IsWindowVisible:


If the specified window, its parent window, its parent window's parent window, etc. have WS_VISIBLE style, the return value is non-zero. Otherwise, the return value is zero.

WS_VISIBLE style indicates that this window is visible in its parent window. But the parent itself may not be visible, in which case IsWindowVisible will return FALSE.

Another thing to note is that if the window is covered by other windows or clipped by its parent window, although the window cannot be seen on the screen at this time, because IsWindowVisible only checks whether the window has the WS_VISIBLE style set, IsWindowVisible will still return TRUE at this time.

Summary

This article once again highlights the importance of the underlying understanding of the system.
knows how to do it and understands the truth, which makes people feel at ease. There are so many knowledge points in
Win32. If you are a child who loves the truth, please follow me and forge ahead.
"Don't build high platforms in the floating sand"

Last

Raymond Chen's "The Old New Thing" is one of the blogs I like very much. It contains a lot of little knowledge about Windows, which is really helpful for the majority of Windows platform developers.
This article comes from: "When is a window visible yet not visible?"