Example #1
0
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
	static Field field;
	HDC hDc;
	PAINTSTRUCT ps;

	static POINT from;
	static POINT to;

	static int a = 0;

	switch( message )
	{
	case WM_PAINT:
		{
			HDC mem = CreateCompatibleDC( 0 );
			hDc = BeginPaint( hWnd, &ps );

			field.Draw( hDc );

			if( a >= 2 )
			{
				int fromCol = from.x / SQUARE_SIZE - 1;
				int fromRow = from.y / SQUARE_SIZE - 1;
				int destCol = to.x / SQUARE_SIZE - 1;
				int destRow = to.y / SQUARE_SIZE - 1;

			//	if( !field.Get( fromRow, fromCol ).isFilled )
			//		return 0;

				bool isSucMove = field.Move( hDc, fromRow, fromCol, destRow, destCol );

				Coordinate coordinate;
				coordinate.row = destCol;
				coordinate.col = destRow; 
				CircleGroup cg;

				cg = field.GetSameColoredCircles( coordinate  );
				if( !field.EraseCircles( cg ) && isSucMove && 
					(
					 ( fromCol != destCol )
					 &&
					 ( fromRow != destRow )
					)
					)
				{
					field.FillWithRandColors( );
				}

				a = 0;
			}

			field.Draw( hDc );
			EndPaint( hWnd, &ps );

			break;
		}
	case WM_LBUTTONDOWN:
		{
			if( a == 0 )
			{
				from.x = LOWORD( lParam );
				from.y = HIWORD( lParam );				
			}
			else
			{
				to.x = LOWORD( lParam );
				to.y = HIWORD( lParam );

				InvalidateRect( hWnd, 0, TRUE );
			}
			a ++;
			break;
		}
	case WM_DESTROY:
		{
			PostQuitMessage( 0 );

			break;
		}
	default:
		{
			return DefWindowProc( hWnd, message, wParam, lParam );
		}	
	}

	return 0;
}