A very high-level view of the process of creating a window in Microsoft Windows
Every Windows program has a WinMain function. This function is analogous to
the "main" function in C. It's where program execution begins. So, the first
step is to create a WinMain function.
Next, create an object of type WNDCLASS. Remember, a "class" is a framework
for a specific type of object. If you have a car, you could define a class
called "car" which specifies that a car object includes information on the
car's color, year of manufacture, etc. Similarly, WNDCLASS is a
Microsoft-defined structure which defines information for a window such as
the window's style.
One very important variable defined in WNDCLASS is the window's procedure
handler. Each window needs a block of code for handling events that happen to
that window. For example, when a window is first drawn on the screen, the
window needs a function in its procedure handler for this event. When you set
up the window using WNDCLASS, remember the name you give to the window's
procedure handler, because you'll need to create a function with that name if
you haven't already.
Register your new window class with the RegisterClass function.
Create a window using the CreateWindow function. Note that this does not
actually *display* the window; it only creates the window as an object in
To show your new window, use the ShowWindow function, then the UpdateWindow
function. The so-called "ShowWindow" function is rather non-intuitive in that
it doesn't actually display what's *IN* the window; it only draws the
window's frame and title bar. To actually display the contents of the window,
you also need to call the UpdateWindow function.
Now that you window has been displayed, you need to start sending it
messages. Almost every event in Microsoft Windows is communicated via
"messages", which are sent to programs by Windows. To read messages that are
created, you need to keep polling the GetMessage function. Once a message has
been received, it needs to be sent to the window with the DispatchMessage
Once DispatchMessage has run, the window's procedure handler takes over, and
based on whatever message it received, it will take action accordingly. This
is typically done with a "switch" statement in the window's procedure
handler, such as "switch(msg)", to do different things based on whatever the