//==============================================================================
//
// TemplWin.cpp 
//
// Template for OS Windows simple application
//
// Developer: Henry Guennadi Levkine
//
// Version 0.02
//
//==============================================================================

#include <windows.h>

//-----------------------------------------------------------------------------
// message handler
//-----------------------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  switch (message) 
  {
    //-----------------------------------
    case WM_DESTROY:
      PostQuitMessage(0);
      break;
    //-----------------------------------
    default:
      return DefWindowProc(hWnd, message, wParam, lParam);
  }
  return 0;
}

//-----------------------------------------------------------------------------
// class registration
//-----------------------------------------------------------------------------
ATOM MyRegisterClass(HINSTANCE hInstance)
{
  WNDCLASSEX wcex;

  wcex.cbSize = sizeof(WNDCLASSEX); 

  wcex.style        = CS_HREDRAW | CS_VREDRAW;
  wcex.lpfnWndProc  = (WNDPROC)WndProc;
  wcex.cbClsExtra   = 0;
  wcex.cbWndExtra   = 0;
  wcex.hInstance    = hInstance;
  wcex.hIcon        = NULL;
  wcex.hCursor      = LoadCursor(NULL, IDC_ARROW);
  wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);
  wcex.lpszMenuName = NULL;
  wcex.lpszClassName= "SimpleWinClass";
  wcex.hIconSm      = NULL;

  return RegisterClassEx(&wcex); 
}

//-----------------------------------------------------------------------------
// create and show application window
//-----------------------------------------------------------------------------
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
  HWND hWnd;

  hWnd = CreateWindow("SimpleWinClass", 
                      "DemoApplication", 
                      WS_OVERLAPPEDWINDOW,
                      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 
                      NULL, 
                      NULL, 
                      hInstance, 
                      NULL);
  if(!hWnd)
  {
    return FALSE;
  }

  ShowWindow(hWnd, nCmdShow);
  UpdateWindow(hWnd);

  return TRUE;
}

//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
  MSG msg;

  MyRegisterClass(hInstance);

  if(!InitInstance(hInstance, nCmdShow))
  {
    return FALSE;
  }

  // Main message loop:
  while(GetMessage(&msg, NULL, 0, 0)) 
  {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }

  return msg.wParam;
}




