#include <windows.h>
#include "w32dry.h"

void draw_text(HDC hDC, int x, int y)
{
  char *string = "Here I am!";
  SetBkMode(hDC, TRANSPARENT);
  SetTextColor(hDC, RGB(128, 128, 255));
  TextOut(hDC, x, y, string, strlen(string));
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) 
{
  switch(msg) {
  case WM_MOUSEMOVE: 
    {
      HDC hDC = GetDC(hWnd);
      draw_text(hDC, LOWORD(lParam), HIWORD(lParam));
      ReleaseDC(hWnd, hDC);
      break;
    }
  case WM_DESTROY:
    PostQuitMessage(0);
    break;
  case WM_PAINT: 
    {
      PAINTSTRUCT paintStruct;
      HDC hDC = BeginPaint(hWnd, &paintStruct);
      draw_text(hDC, 150, 150);
      EndPaint(hWnd, &paintStruct);
      break;
    }
  default:
    return DefWindowProc(hWnd, msg, wParam, lParam);
  }
  return 0;
}

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpCmdLine,
                     int nCmdShow)
{
  WNDCLASSEX windowClass;
  window_instance win;
  init_window_classex(&windowClass, &win, hInstance, WndProc, "AClass");
  if (!RegisterClassEx(&windowClass)) return 1;
  win.title = "Following the mouse";
  if (!create_window(&win, 400, 400)) return 1;
  ShowWindow(win.hWnd, nCmdShow);
  return message_loop();
}
