I'm trying to understand the way WTL works, and message loops are confusing me right now.
For example this code fragment: link
The window is first created and after that the message pump is started. How come it works? Isn't the CreateEx, UpdateWindow and so on supposed to send their own invisible messages like WM_CREATE/WM_PAINT/WM_NCPAINT? Where are they thrown if the message pump is not initialized? What happens if you create a window, start message loop, then close the window, but want to create a new one in it's place? PostQuit exits the loop and you have to create a new one?
Understanding the difference between posting messages (PostMessage) and sending messages (SendMessage) is important here. Windows calls the window procedure directly for sent messages, they are not dispatched by the message loop. Which is how WM_CREATE and WM_SHOWWINDOW can be processed before the message loop is started. WM_QUIT, WM_PAINT, WM_KEYDOWN and WM_MOUSEMOVE are examples of messages that are posted.