Jeesh, I feel out of place asking all these questions, but hey... the only stupid question is the one not asked right?

Anyway, what is the prefered way to create a window? In response to WM_PAINT (as some examples) or in WinMain (or some other place that I use)? Right now I create all my windows (Window, controls) in either WinMain or some other proc that I use which seems to work fine, but I see some create everything in response to WM_PAINT, Which way?
Posted on 2002-06-22 22:56:48 by Gunner
the preferred way to create a window is in WinMain(in my case before the message loop), for window controls is during the WM_CREATE. Don't even try to create a window during a WM_PAINT. This is one of the messages that are always passed to your application. Everytime you move, restore a window ... Windoze(OS) always sends a WM_PAINT to your window this means for every WM_PAINT message there is always a call to CreateWindow. This is not a good thing. In my opinion it's bad programming practice, but hey! no ones gonna stop you from doing/testing it.
Posted on 2002-06-22 23:05:03 by stryker
if you're talking child windows, then WM_CREATE is probably the best. but CreateWindowEx sends WM_CREATE to the message loop, so if you don't call it at some point before the message loop, the message will never get sent.
Posted on 2002-06-23 00:51:56 by Sloat

The way it works is that you register a class first then create the main window with CreateWindowEx. In the WNDCLASSEX structure you assign an address where the OS will post the messages for the window that uses that class.

The WM_CREATE is an interesting case, it is not really part of the normal message handling procedure, it is only ever called once when the CreateWindowEx function is called in the WinMain procedure. The code you place in the WM_CREATE message is executed only then and thats why its often used for startup code.

Posted on 2002-06-23 02:11:14 by hutch--