First a caveat, I only very recently started learning about the WinAPI. I'm sure this question has been asked many times before, but for some reason I can't find it anywhere online. The question is simply this; why bother with the initial call to ShowWindow()
in the body of WinMain()
before the execution of the message loop? Why not simply set the window to be initially visible through use of the WS_VISIBLE
flag?
I also have some questions as to the mechanics of the ShowWindow()
function. Which messages does it actually send? In MSDN it states that:
If a window has the
WS_VISIBLE
style when it is created, the window receives this message[WM_SHOWWINDOW]
after it is created, but before it is displayed. A window also receives this message when its visibility state is changed by theShowWindow
orShowOwnedPopups
function.
Does this mean the primary means of communication between the ShowWindow()
function and Windows is through the WM_SHOWWINDOW
message? It also states that:
The
WM_SHOWWINDOW
message is not sent under the following circumstances:
When a top-level, overlapped window is created with the
WS_MAXIMIZE
orWS_MINIMIZE
style.When the
SW_SHOWNORMAL
flag is specified in the call to theShowWindow
function.
The MSDN also states that:
The first time an application calls
ShowWindow
, it should use theWinMain
function'snCmdShow
parameter as itsnCmdShow
parameter.
Petzold states that the argument passed to this nCmdShow
parameter will be either SW_SHOWNORMAL
, SW_SHOWMAXIMIZED
or SW_SHOWMINNOACTIVE
. Am I to take from this that the only time the ShowWindow()
function does not send a WM_SHOWWINDOW
message, is when we make that very first initial call to it in Winmain()
? If so, how does it then get the window to display? Also, how does all of this relate to the actual painting of the window?
I'm sorry if my question is bit of a jumbled mess, but the mechanics of showing a window kind of confuse me, and for some reason it's hard to find clear answers to these questions online (as opposed to just bits and pieces of information). Any help in clarifying all of this will be greatly appreciated!