Patrick’s development blog

Preparing the Win32 API

Posted in Uncategorized by Patrick on March 25, 2008

I’ve started to learn a little Windows coding using its API today. I’m preparing it for my chat application i’m going to make in C++. Here’s how a typical hello world program looks like when coding in win32. It displays a message box on the screen which says “Hello world”.

Hello world in Win32

#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
MessageBox(NULL, TEXT(“Hello world!”), TEXT(“Message”), 0);
return 0;

WinMain is the same as the main() function in C and C++ (the entry point of the application).

The hInstance parameter is a handler to the current window. It seems that the second parameter hPrevInstance isn’t used anymore. It was used to keep track of other instances of the same application. Last time it was used was in 16-bit Windows. The parameter is always NULL.

The third parameter szCmdLine takes care of the commands the application is started with.

The last parameter iCmdShow indicates how the program should be displayed, for example if it’s going to be maximized, minimized or hidden.


Chat application

Posted in Uncategorized by Patrick on March 24, 2008

My next project I have in mind, is going to be a chat application in C++. This is project is originally something we’re doing in school and I chose to make an internet chat with a server and a client. I haven’t thought out all the details about the project yet, but I started on it a couple of weeks ago. In the beginning, I had decided to use SDL because it’s easy to use when making graphical applications and it also has SDLnet for networking. My plans has changed however.

In order to implement a GUI, I decided to use the Win32 API together with C++. I know from experience that Win32 coding is quite nasty and extremely hard, so I hope i’ll pull it off somehow.