Dave's Brain

Browse - programming tips - win32 is a point inside a rectangle

Date: 2010mar1
Platform: win32
Language: C/C++

Q.  How can I check if a point is inside a rectangle?

A.  Here's a function that does that:

	// Make sure both are in the same co-ordinates
	BOOL IsInside(const RECT &rect, const POINT point)
	{
		return !(point.x < rect.left || point.x > rect.right || point.y < rect.top || point.y > rect.bottom);
	}

	ExampleUse()
	{
		RECT		rect;
		POINT		point;

		// ...

		if (IsInside(rect, point))
		{
			printf("Inside\n");
		}
		else
		{
			printf("Outside\n");
		}
	}

In MFC you can use CRect::PtInRect()
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.