The first chapter of --HelloWorld WIN32 version

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Windows programming Fifth Edition P13

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow )
        MessageBox( NULL, TEXT("Hello, Windoows 98!"), TEXT("HelloMsg"), 0);

        return 0;


The main function:

int WINAPI WinMain

Is the entrance of the WIN32 function, and C in the int main

One, the main function and its parameters:

The MSDN WinMain statement:

int WINAPI WinMain(
  HINSTANCE hInstance,      // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,          // command line
  int nCmdShow              // show state

The first parameter is generally called "the instance handle". Used to identify something in Windows program. This example used to uniquely identify the program

The first parameter, used in earlier versions of WINDOWS, at 32 WINDOWS, is no longer in use. Always NULL (defined as 0)

Third parameters, the original type is LPSTR, the prefix LP means long pointer, which is a 16 bit WINDOWS product. Its role is to run the application from the command line. Some WINDOWS program at boot time to use it to put the file is loaded into memory.

The fourth parameter, used to specify the program initially how to display. Discussed in the third chapter

Two, the MessageBox function

Used to display the short information, form a single, small window which show is actually a dialog box.

In the MASDN statement:

int MessageBox(
  HWND hWnd,          // handle to owner window
  LPCTSTR lpText,     // text in message box
  LPCTSTR lpCaption,  // message box title
  UINT uType          // message box style

The first parameter, is usually a window handle, in third Zhang Jieshi

Second parameters, shown in the dialog box text

Third parameters, shown in the dialog title bar text

These two parameters in front of the TEXT is a macro, the program into Unicode will facilitate a lot. Explained in detail in the second chapter

The fourth parameter, and the ICON dialog box button style

This parameter can be used C | symbols combined with ICON, can also set the default button, such as:



If coupled with the MB_DEFBUTTON, you can set the default button, such as:


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Ricky at December 30, 2013 - 4:38 AM