
/*
 * I. ARIT 1992 Hidirbeyli,AYDIN,TR.  09400 Golden,    CO,   USA. 80401 
 *
 *
 * Copyright (C) 1992 Ismail ARIT 
 *
 * This file is distributed in the hope that it will be useful,but without any
 * warranty.  No author or distributor accepts responsibility to anyone for
 * the consequences of using it or for whether it serves any particular
 * purpose or works at all. 
 *
 *
 * Everyone is granted permission to copy, modify and redistribute this file
 * under the following conditions: 
 *
 * Permission is granted to anyone to make or distribute copies of the source
 * code, either as received or modified, in any medium, provided that all
 * copyright notices, permission and nonwarranty notices are preserved, and
 * that the distributor grants the recipient permission for further
 * redistribution as permitted by this document.
 *
 * No part of this program can be used in any commercial product.
 */



#include <windows.h>
#include <stdlib.h>
#include "definiti.h"



TwoPlayer       My;

extern HWND hWndMain;
extern HWND DialogWinHandle ;
extern int WantsTrajectory ;






BOOL FAR PASCAL
PlayersHandleDlgProc(hDlg, iMessage, wParam, lParam)
	HWND            hDlg;
	WORD            iMessage;
	WORD            wParam;
	LONG            lParam;
{



	switch (iMessage) {
	case WM_INITDIALOG:

		SetDlgItemText(hDlg, PLAYER1, My.Player1String);
		SetDlgItemText(hDlg, PLAYER2, My.Player2String);

		break;



	case WM_COMMAND:
		switch (wParam) {
		case PLAYER1:
			if (HIWORD(lParam) == EN_CHANGE) {
				EnableWindow(GetDlgItem(hDlg, IDOK),
					  (BOOL) SendMessage(LOWORD(lParam),
						  WM_GETTEXTLENGTH, 0, 0L));
			}
			break;

		case PLAYER2:
			if (HIWORD(lParam) == EN_CHANGE) {
				EnableWindow(GetDlgItem(hDlg, IDOK),
					  (BOOL) SendMessage(LOWORD(lParam),
						  WM_GETTEXTLENGTH, 0, 0L));
			}
			break;





		case PLAYER_OK:

			GetDlgItemText(hDlg, PLAYER1, My.Player1String, 30);
			GetDlgItemText(hDlg, PLAYER2, My.Player2String, 30);
			EndDialog(hDlg, TRUE);
			break;




		case PLAYER_CANSEL:
			/* Terminate this dialog box. */
			EndDialog(hDlg, FALSE);
			break;



		default:
			return (FALSE);
		}		/* end of switch  wParam */
		break;

	default:
		return (FALSE);
	}

	return (TRUE);
}






int 
GetPlayersName(HANDLE hinst, HWND hwnd)
{

	int             iReturn;
	FARPROC         lpfnHandleDlgProc;



	lpfnHandleDlgProc = MakeProcInstance(PlayersHandleDlgProc, hinst);

	iReturn = DialogBox(hinst,
			    MAKEINTRESOURCE(PLAYERS),
			    hwnd,
			    lpfnHandleDlgProc);

	FreeProcInstance(lpfnHandleDlgProc);

	return (iReturn);
}




BOOL FAR PASCAL 
ScoresHandleDlgProc(hDlg, iMessage, wParam, lParam)
	HWND            hDlg;
	WORD            iMessage;
	WORD            wParam;
	LONG            lParam;
{
	char            temp[30];



	switch (iMessage) {
	case WM_INITDIALOG:
		wsprintf(temp, "%d", My.Player1Score);
		SetDlgItemText(hDlg, PLAYER1_SCORE, temp);

		wsprintf(temp, "%d", My.Player2Score);
		SetDlgItemText(hDlg, PLAYER2_SCORE, temp);

		break;



	case WM_COMMAND:
		switch (wParam) {
		case PLAYER1_SCORE:
			if (HIWORD(lParam) == EN_CHANGE) {
				EnableWindow(GetDlgItem(hDlg, IDOK),
					  (BOOL) SendMessage(LOWORD(lParam),
						  WM_GETTEXTLENGTH, 0, 0L));
			}
			break;

		case PLAYER2_SCORE:
			if (HIWORD(lParam) == EN_CHANGE) {
				EnableWindow(GetDlgItem(hDlg, IDOK),
					  (BOOL) SendMessage(LOWORD(lParam),
						  WM_GETTEXTLENGTH, 0, 0L));
			}
			break;




		case PLAYER1_PLUS:
			GetDlgItemText(hDlg, PLAYER1_SCORE, temp, 30);
			My.Player1Score = atoi(temp);

			My.Player1Score += 1;
			wsprintf(temp, "%d", My.Player1Score);
			SetDlgItemText(hDlg, PLAYER1_SCORE, temp);
			break;


		case PLAYER1_MINUS:
			GetDlgItemText(hDlg, PLAYER1_SCORE, temp, 30);
			My.Player1Score = atoi(temp);

			My.Player1Score -= 1;
			wsprintf(temp, "%d", My.Player1Score);
			SetDlgItemText(hDlg, PLAYER1_SCORE, temp);
			break;





		case PLAYER2_PLUS:
			GetDlgItemText(hDlg, PLAYER2_SCORE, temp, 30);
			My.Player2Score = atoi(temp);

			My.Player2Score += 1;
			wsprintf(temp, "%d", My.Player2Score);
			SetDlgItemText(hDlg, PLAYER2_SCORE, temp);
			break;

		case PLAYER2_MINUS:
			GetDlgItemText(hDlg, PLAYER2_SCORE, temp, 30);
			My.Player2Score = atoi(temp);

			My.Player2Score -= 1;
			wsprintf(temp, "%d", My.Player2Score);
			SetDlgItemText(hDlg, PLAYER2_SCORE, temp);
			break;




		case SCORES_OK:


			GetDlgItemText(hDlg, PLAYER1_SCORE, temp, 30);
			My.Player1Score = atoi(temp);
			GetDlgItemText(hDlg, PLAYER2_SCORE, temp, 30);
			My.Player2Score = atoi(temp);
			EndDialog(hDlg, TRUE);
			break;




		case SCORES_CANSEL:
			/* Terminate this dialog box. */
			EndDialog(hDlg, FALSE);
			break;



		default:
			return (FALSE);
		}		/* end of switch  wParam */
		break;

	default:
		return (FALSE);
	}

	return (TRUE);
}


int 
GetScores(HANDLE hinst, HWND hwnd)
{

	int             iReturn;
	FARPROC         lpfnHandleDlgProc;



	lpfnHandleDlgProc = MakeProcInstance(ScoresHandleDlgProc, hinst);

	iReturn = DialogBox(hinst,
			    MAKEINTRESOURCE(SCORES),
			    hwnd,
			    lpfnHandleDlgProc);

	FreeProcInstance(lpfnHandleDlgProc);

	return (iReturn);
}







BOOL FAR PASCAL
FloatHandleDlgProc(hDlg, iMessage, wParam, lParam)
	HWND            hDlg;
	WORD            iMessage;
	WORD            wParam;
	LONG            lParam;
{



	switch (iMessage) {


	case WM_COMMAND:
		switch (wParam) {

	       case FNewGame :
		   SendMessage(hWndMain,WM_COMMAND,NewGame,0L);
		   break;


case FLoadGame :
		   SendMessage(hWndMain,WM_COMMAND,LoadGame,0L);
		   break;


case FPlayers   :
		   SendMessage(hWndMain,WM_COMMAND,Players,0L);
		   break;

case FScores    :
		   SendMessage(hWndMain,WM_COMMAND,Scores,0L);
		   break;

case FSaveIt     :
		   SendMessage(hWndMain,WM_COMMAND,SaveIt,0L);
		   break;



case FAboutBox     :
		   SendMessage(hWndMain,WM_COMMAND,AboutBox,0L);
		   break;

case FTrajectoryMode :
			WantsTrajectory = !WantsTrajectory;

			if (WantsTrajectory == YES)
			    SendDlgItemMessage(hDlg, FTrajectoryMode, BM_SETCHECK, TRUE, 0);
			else
			    SendDlgItemMessage(hDlg, FTrajectoryMode, BM_SETCHECK, FALSE, 0);


		   break;




	      case FExitThisApp :

			/* Terminate this dialog box. */
			DestroyWindow(DialogWinHandle);
			SendMessage(hWndMain,WM_CLOSE,0,0L);
			break;



		default:
			return (FALSE);
		}		/* end of switch  wParam */
		break;

	default:
		return (FALSE);
	}

	return (TRUE);
}



