CRect::IntersectRect
BOOL IntersectRect( LPCRECT lpRect1, LPCRECT lpRect2 );ResMakes a CRect equal to the intersection of two existing rectangles. The intersection is the largest rectangle contained in both existing rectangles.Note Both of the rectangles must be normalized or this function may fail. You can call NormalizeRect to normalize the rectangles before calling this function.ExampleCRect rectOne(125, 0, 150, 200);
CRect rectTwo( 0, 75, 350, 95);
CRect rectInter;rectInter.IntersectRect(rectOne, rectTwo);// rectInter is now (125, 75, 150, 95)ASSERT(rectInter == CRect(125, 75, 150, 95));// operator &= can do the same task:CRect rectInter2 = rectOne;
rectInter2 &= rectTwo;
ASSERT(rectInter2 == CRect(125, 75, 150, 95));用这个函数试试
BOOL IntersectRect( LPCRECT lpRect1, LPCRECT lpRect2 );ResMakes a CRect equal to the intersection of two existing rectangles. The intersection is the largest rectangle contained in both existing rectangles.Note Both of the rectangles must be normalized or this function may fail. You can call NormalizeRect to normalize the rectangles before calling this function.ExampleCRect rectOne(125, 0, 150, 200);
CRect rectTwo( 0, 75, 350, 95);
CRect rectInter;rectInter.IntersectRect(rectOne, rectTwo);// rectInter is now (125, 75, 150, 95)ASSERT(rectInter == CRect(125, 75, 150, 95));// operator &= can do the same task:CRect rectInter2 = rectOne;
rectInter2 &= rectTwo;
ASSERT(rectInter2 == CRect(125, 75, 150, 95));用这个函数试试
不对
CRect rectTwo( 0, 75, 350, 95);
CRect rectInter;rectInter.IntersectRect(rectOne, rectTwo);// rectInter is now (125, 75, 150, 95)这里不是还有一个例子吗,主要让你看这个函数的功能啊
ASSERT(rectInter == CRect(125, 75, 150, 95));
我要求属于A
不属于B
的那一部分
或者,你直接用这个函数吧
PtInRect
This function determines whether the specified point lies within the specified rectangle. A point is within a rectangle if it lies on the left or top side or is within all four sides. A point on the right or bottom side is considered outside the rectangle. BOOL PtInRect(
const RECT *lprc,
POINT pt );
对于每一个用到的点都判断是不是在A里不在B里面
假如有一个矩形Rect1,顶点是A,B,C,D,另外有一个矩形Rect2和他相交,相交后的矩形Rect3有一个顶点落在Rect1内,这个点是G,那么,这个点就把Rect1分成了4个小矩形,其中有一个是Rect3,那么另外3个就是你所要求的矩形了,对于有2个,4个顶点落在Rect1内的情况你可以自己分析
想问题要自己多动动脑筋,在vc里面没有这样的函数,但是我们可以编程解决这个问题,如果还是不明白,给我写信吧[email protected]这样讨论的话方便一些