If you are planning to program the Win32 SDK, or the Platform SDK, you must know C++ very well. If you don't I highly recommend starting with my regular C++ tutorials, which systematically introduce all that C++ has to offer. However, if you understand C++ proficiently and show a desire to learn the Win32 SDK, continue reading.

The Win32 SDK is used for 32-bit versions of Windows, i.e. Win95, Win98, and WinNT. Windows 3.11 is 16-bit and I never learned how to program it, so I can't help you out with it. However, I could not possibly see why you would want to program for an outdated version of the Windows OS.

The first tutorial will introduce something very familiar from Win95/Win98: the Message Box. Why a message box? Well, first off, it is very easy to program, and second, it is in reality a type of window, and isn't that our goal here, to program Windows? Besides, I guarantee later on you will you Message Boxes in your Windows Programs.

I assume that you are using MicroSoft Visual C++ 6.0. If you are unfamiliar with setting up the compiler, refer to C++ lesson 1. However, instead of choosing to create a console mode project, create an empty Win32 Application.

I will first provide the source code, which you should manually type to get the commands drilled into your head, and then I will explain. So here's the code for your first Windows program:

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
{

MessageBox(NULL, "What's up, Dude?!", "My Own Windows Program", MB_OK);

return (0);
}

If you're perceptive enough, you realized that there in no longer a main () function. The main () function is native to console mode programming and is replaced in Windows programming by WinMain (). You may have noticed that the WinMain() function was called with 4 parameters, which must be there as a 32-bit calling convention, otherwise other parameters may be passed and things could get ugly quickly. All you need to know is that whenever your going to start the main programming of your Windows program, you define it exactly as above, with the WINAPI prename and all.

It is essential to remember that when programming Windows, we are using an SDK (Software Develpment Kit) known as the Platform SDK. Like all SDKs, the Platform SDK comes loaded with its own set of functions. The usage and parameters of each function may be found in the Platform SDK's help files. The MessageBox call is such a function.

The MessageBox function takes 4 parameters and is defined as such:

int MessageBox(
HWND hWnd, // Handle to a parent window (since we had no parent window, this value was NULL)
LPCTSRT lpText, // Pointer to the message box's message
LPCTSTR lpCaption, // Pointer the message box's title
UINT uType); // style of message box

To understand all of these parameters, you must be accustomed to the Hungarian naming convention. However, since you should be familiar with C++, you should be familiar with this naming scheme (e.g. UINT = unsigned int).

The style types of the Message Box are numerous. You should be able to find all the values in the help files, but if you cannot, notify me and I'll post them. But the information is so much, and you should already have it all, that it would truly be a waste for me to post it. Off the top of my head, I can only think of a couple styles. I primarily use MB_OK and MB_ERROR.

For practice, I encourage you to consult the SDK's help system, get the other style values, and then alter the program around a little. If you want to trick your friends intor thinking that their is something wrong with their computer, create a Message Box with a style of MB_ERROR, and create some fantastic error message and title for it! *NOTE: You cannot use formatted text directly. The only way that you can use formatted text is by accessing it through a string array. Keep this in mind when changing the code around.

Well that's all for this tutorial. I hope that it at least satisfies that craving to program Windows a little. There is a lot of information involved to programming Windows. I hope to cover more in the next tutorial.

The source files for this lesson can be downloaded here.