/****************************************************************************
  
May 30, 1990 ... 6:29 AM
  
    PROGRAM: pcmove.c
    PURPOSE: Creates an edit window
    FUNCTIONS:
	WinMain() - calls initialization function, processes message loop
	FileMoveInit() - initializes window data and registers window
	FileMoveWndProc() - processes messages
	About() - processes messages for "About" dialog box
    COMMENTS:
	After setting up the application's window, the size of the client
	area is determined and a child window is created to use for editing.
****************************************************************************/

#include "pcmove.h"

HANDLE hInst = 0;
HANDLE hAccTable;


/****************************************************************************
    FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
    PURPOSE: calls initialization function, processes message loop
****************************************************************************/
int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  HANDLE hInstance;
  HANDLE hPrevInstance;
  LPSTR lpCmdLine;
  int nCmdShow;
{
  HWND hWnd;			/* window handle	     */
  MSG msg;			/* message	     */

  if (!hPrevInstance)		/* Has application been initialized? */
    if (!FileMoveInit(hInstance))
      return (NULL);		/* Exits if unable to initialize     */
  hInst = hInstance;		/* Saves the current instance	     */

  hWnd = _CreateWindow("PCMove",	/* window class	     */
		      "File Moving Utility for PC Magazine",	/* window name	     */
		      WS_OVERLAPPEDWINDOW,	/* window style	     */
		      CW_USEDEFAULT,	/* x position	     */
		      CW_USEDEFAULT,	/* y position	     */
		      CW_USEDEFAULT,	/* width	     */
		      CW_USEDEFAULT,	/* height	     */
		      NULL,	/* parent handle	     */
		      NULL,	/* menu or child ID	     */
		      hInstance,/* instance	     */
		      NULL);	/* additional info	     */
  if (!hWnd)			/* Was the window created? */
    return (NULL);


  ShowWindow(hWnd, nCmdShow);	/* Shows the window	     */
  UpdateWindow(hWnd);		/* Sends WM_PAINT message  */
#ifdef MEWEL
  SetFocus(hWnd);
#endif


  while (GetMessage(&msg,	/* message structure	     */
		    NULL,	/* handle of window receiving the message */
		    NULL,	/* lowest message to examine	     */
		    NULL))	/* highest message to examine	     */
  {
#ifdef MEWEL
    TranslateAccelerator(&msg);
#endif
    TranslateMessage(&msg);	/* Translates virtual key codes	     */
    DispatchMessage(&msg);	/* Dispatches message to window	     */
  }
  return (msg.wParam);		/* Returns the value from PostQuitMessage */
}

/****************************************************************************
    FUNCTION: FileMoveInit(HANDLE)
    PURPOSE: Initializes window data and registers window class
****************************************************************************/
BOOL FileMoveInit(hInstance)
  HANDLE hInstance;
{
  MEMHANDLE hMemory;
  PWNDCLASS pWndClass;
  BOOL bSuccess;

  hMemory = LocalAlloc(LPTR, sizeof(WNDCLASS));

  pWndClass = (PWNDCLASS) LocalLock(hMemory);
  pWndClass->hCursor       = LoadCursor(NULL, IDC_ARROW);
  pWndClass->hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  pWndClass->lpszMenuName  = (LPSTR) "PCMove";
  pWndClass->lpszClassName = (LPSTR) "pcmove";
  pWndClass->hbrBackground = GetStockObject(WHITE_BRUSH);
  pWndClass->hInstance     = hInstance;
  pWndClass->style         = NULL;
  pWndClass->lpfnWndProc   = FileMoveWndProc;

  bSuccess = RegisterClass(pWndClass);

  LocalUnlock(hMemory);
  LocalFree(hMemory);
  return (bSuccess);
}

/****************************************************************************
    FUNCTION: FileMoveWndProc(HWND, unsigned, WORD, LONG)
    PURPOSE:  Processes messages
    MESSAGES:
	WM_SYSCOMMAND - system menu (About dialog box)
	WM_CREATE     - create window and objects
	WM_DESTROY    - destroy window
	WM_SIZE	      - window size has changed
    COMMENTS:
	When a WM_SIZE message is received, the edit window must be resized
	to match the parent's client area.
****************************************************************************/
long FAR PASCAL FileMoveWndProc(hWnd, message, wParam, lParam)
  HWND hWnd;
  unsigned message;
  WORD wParam;
  LONG lParam;
{
  FARPROC lpProcAbout, lpProcPCMove;

  switch (message)
  {
  case WM_COMMAND:
    switch (wParam)
    {
      case IDM_EXIT:
        PostQuitMessage(0);
        break;

      case IDM_ABOUT:
        lpProcAbout = MakeProcInstance(About, hInst);
        _DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
        FreeProcInstance(lpProcAbout);
        break;

      case IDM_TOINBOX:
        lpProcPCMove = MakeProcInstance(OpenDlg, hInst);
        _DialogBox(hInst, "OpenDlg", hWnd, lpProcPCMove);
        FreeProcInstance(lpProcPCMove);
        break;

      case IDM_FROMINBOX:
#ifdef PCMAG
        lpProcPCMove = MakeProcInstance(OpenDlg2, hInst);
        _DialogBox(hInst, "OpenDlg2", hWnd, lpProcPCMove);
        FreeProcInstance(lpProcPCMove);
#endif
        break;
    }
    break;

  case WM_DESTROY:
    PostQuitMessage(0);
    break;

  default:
    return DefWindowProc(hWnd, message, wParam, lParam);
  }
  return (NULL);
}

/****************************************************************************
    FUNCTION: About(HWND, unsigned, WORD, LONG)
    PURPOSE:  Processes messages for "About" dialog box
    MESSAGES:
	WM_INITDIALOG - initialize dialog box
	WM_COMMAND    - Input received
****************************************************************************/
BOOL FAR PASCAL About(hDlg, message, wParam, lParam)
  HWND hDlg;
  unsigned message;
  WORD wParam;
  LONG lParam;
{
  switch (message)
  {
  case WM_INITDIALOG:
    return (TRUE);
  case WM_COMMAND:
    if (wParam == IDOK)
    {
      EndDialog(hDlg, TRUE);
      return (TRUE);
    }
    break;
  }
  return (FALSE);
}


#ifdef MEWEL
main()
{
  WinInit();
  WinUseSysColors(NULLHWND, TRUE);
  return WinMain(hInst, 0, (LPSTR) NULL, TRUE);
}
#endif

