#include <stdio.h>
#include "window.h"
#include "keys.h"

int  (pascal *OldMainWinProc)();
extern int pascal MainWndProc();
HWND hMain;
HWND hMouseWnd;


main(argc, argv)
  int  argc;
  char **argv;
{
  EVENT  event;

  /*
    Initialize the window system - this *must* be done once in every appl
  */
  WinInit();
  /*
    Create the main window and set the main window procedure
  */
  hMain = WinCreate(NULLHWND, 0, 0, 24, 79, "Mouse Demo", 0x17,
 			          	 (WIN_HAS_BORDER), NORMAL_CLASS, 0);
  OldMainWinProc = WinSetWinProc(hMain, MainWndProc);

  hMouseWnd = WinCreate(hMain, 10, 30, 12, 50, "Mouse Coordinates", 0x31,
 			          	 (WIN_HAS_BORDER), NORMAL_CLASS, 0);

  WinDraw(hMain);
  SetFocus(hMain);

  /*
    Main message loop
  */
  for (;;)
  {
    GetMessage(&event);
    TranslateAccelerator(&event);
    DispatchMessage(&event);
  }
}

/*
  MainWndProc - window procedure for the main window
*/
int pascal MainWndProc(hWnd, message, wParam, lParam)
  HWND hWnd;
  WORD message;
  WORD wParam;
  DWORD lParam;
{
  int mouserow, mousecol;
  char buf[80];

  switch (message)
  {
    case WM_QUIT       :
      /* End the dialog editor */
      VidClearScreen(0x07);
      exit(0);

    case WM_CHAR       :
      PostQuitMessage(0);
      break;

    case WM_MOUSEMOVE  :
      mouserow = HIWORD(lParam);
      mousecol = LOWORD(lParam);
      sprintf(buf, "ROW [%2d]  COL [%2d]", mouserow, mousecol);
      WinPutsCenter(hMouseWnd, 0, buf, 0x31);
      break;

    default :
      /* Call the default window procedure for the main window */
      return DefWinProc(hWnd, message, wParam, lParam);
  }
}

