// WINAPP1.CPP   A simple Windows application in C++

#include <windows.h>

// Declaration of the window message-handling procedure
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);

// The WinMain function definition--execution begins here
int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                                      LPSTR lpszCmdLine, int nCmdShow)
{
        HWND        hWnd;               // window's handle 
        MSG         msg;                // a message structure 
        WNDCLASS    wndclass;   // window class structure 

        // Set up a new window class with desired properties 
        wndclass.style          = CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc    = WndProc;
        wndclass.cbClsExtra     = 0;
        wndclass.cbWndExtra     = 0;
        wndclass.hInstance      = hInstance;
        wndclass.hIcon          = NULL;
        wndclass.hCursor        = NULL;
        wndclass.hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH);
        wndclass.lpszMenuName   = NULL;
        wndclass.lpszClassName  = TEXT("MyClass");

        // try to register the new class
        if (!RegisterClass (&wndclass))
                return(0);
        
        // Create the window
        hWnd = CreateWindow (TEXT("MyClass"),TEXT ("My First Window"), 
                WS_OVERLAPPEDWINDOW,10,10,200,100,NULL,NULL,hInstance,NULL);

        ShowWindow (hWnd, nCmdShow);          // display the window 
        UpdateWindow (hWnd);                  // paint client area    

        while (GetMessage (&msg, NULL, 0, 0)) // message loop 
        {
                DispatchMessage (&msg) ;      // Tell Windows to send new... 
        }                                     // message to the class WndProc 
        return ((int)msg.wParam);                  // Quit 

}


// WndProc() -- custom function for processing Windows messages
LRESULT CALLBACK WndProc (HWND hWnd, UINT wMessage,
                                             WPARAM wParam, LPARAM lParam)
{
        switch (wMessage)               // determine what kind of message 
        {

        case WM_DESTROY:                // determine what kind of message 
                PostQuitMessage(0);     // put WM_QUIT msg in pgm's msg Q 
                break ;                 // break out of switch statement

        default:                        // default Windows message processing
                return DefWindowProc(hWnd,wMessage,wParam,lParam);
        }

        return(0);

}