Before reading this article, the reader should use the following article as a starting point - The Win32 Programming Paradigm. Once the paradigm is understood, it makes the programming that much easier.
The WinMain function is the entry point, and is similar to the main function used in regular C programming. Unlike console (command line) programming, it has to explicity register the applications look and feel with Windows, and provide a message loop for processing incoming messages.
If this sounds a little daunting, then it is worth remembering that Windows process much of the specifics itself - the WinMain function simply provides a starting point. As such, the following skeleton can be re-used as many times as necessary, only adjusting, where necessary, some of the values from project to project.
Most of the customisation will take place in the wndclass variable. This gives the various attributes associated with the application, from the cursor and icon, through to the color used to paint the background. After all the parameters (which should be failry self-explanatory from the names) have been set, the class is registered with a call to RegisterClass.
This enables Windows to re-use the definition if another copy of the class appears in the system. To run several instances at the same time in this way, and keep them logically seperate, the hInstance variable is used. The WndProc referred to is the function that actually processes the users interaction with the application. This needs to be provided by the programmer as well, and will be covered in a later article.
All that the CreateWindow function does is set up the window, in the correct place and at the correct size, and give it a title in the title bar. Every piece of the Windows GUI (including buttons, text boxes, etc.) will be created with a call to CreateWindow. Once it is set up, the messages associated with it have to be processed.
This is done in the message loop. The while loop simply takes messages from the queue, and returns out of the function when there are nonen left. TranslateMessage turns key codes into real virtual keys, and DispatchMessage sends the message to WndProc for processing.
Feel free to cut and paste the above WinMain function in its entirety. Do not forget, however, to change the szAppName and szAppTitle variables, otherwise the result will not be quite as intended. Other values are also open to customisation, including:
Also, if a menu is required, the lpszMenuName member of the WNDCLASS must be set to the same value as that used in the resource file that accompanies the application code. If a resource file is not included in the project, then the Borland compiler will simply ignore the lpszMenuName member, and build a menu-less (resource-less) application.
For more details on building an application with the free Borland compiler and tools, please refer to the Borland Win32 Compiler Guide.