/* The original version of this program can be found at http://damb.dk */
#include <windows.h>

HINSTANCE InstanceHandle;
HWND      MainWindow;

void Draw(HDC aDc)
{
   RECT R;
   GetWindowRect(MainWindow, &R);
   int Width = (R.right - R.left + 3)/4;
   int Height = (R.bottom - R.top + 3)/4;
   POINT UpperLeft = {R.left - Width, R.top};
   HDC DC = GetDC(0);
   StretchBlt(aDc,
              0,
              0,
              Width*4,
              Height*4,
              DC,
              UpperLeft.x,
              UpperLeft.y,
              Width,
              Height,
              SRCCOPY);

   ReleaseDC(0, DC);
}

LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
   switch (msg)
   {
   case WM_DESTROY:
      PostQuitMessage(0);
      break;
   case WM_MOVE:
      HDC Dc;
      Dc = GetDC(hwnd);
      Draw(Dc);
      ReleaseDC(hwnd, Dc);
      break;
   case WM_PAINT:
      PAINTSTRUCT PaintStruct;
      HDC dc;
      dc = BeginPaint(hwnd, &PaintStruct);
      Draw(dc);
      EndPaint(hwnd, &PaintStruct);
      break;
   default:
      return DefWindowProc(hwnd,msg,wParam,lParam);
   }
   return 0;
}

HWND CreateMainWindow()
{
   WNDCLASS wc;
   memset(&wc, 0, sizeof(WNDCLASS));
   wc.style = CS_HREDRAW | CS_VREDRAW  | CS_DBLCLKS ;
   wc.lpfnWndProc = (WNDPROC )MainWndProc;
   wc.hInstance = InstanceHandle;
   wc.hbrBackground = (HBRUSH )(COLOR_WINDOW + 1);
   wc.lpszClassName = "SimpleWinWndClass";
   wc.lpszMenuName = 0;
   wc.hCursor = LoadCursor(NULL, IDC_ARROW);
   wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
   if(!RegisterClass(&wc))
      return 0;

   return CreateWindow("SimpleWinWndClass",
                       "MagnifyingGlass",
                       WS_MINIMIZEBOX | WS_VISIBLE |
                       WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_MAXIMIZEBOX |
                       WS_CAPTION | WS_BORDER | WS_SYSMENU | WS_THICKFRAME,
                       100, 100, 100, 100,
                       0,
                       0,
                       InstanceHandle,
                       0);
}

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   INT nCmdShow)
{
   InstanceHandle = hInstance;

   if((MainWindow = CreateMainWindow()) == (HWND )0)
   {
      MessageBox(0, "Failed to create MainWindow!", "Warning", MB_OK);
      return 0;
   }
   ShowWindow(MainWindow, SW_SHOW);
   MSG Msg;
   while(GetMessage(&Msg, 0, 0, 0))
   {
      TranslateMessage(&Msg);
      DispatchMessage(&Msg);
   }
   return Msg.wParam;
}