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));用这个函数试试

解决方案 »

  1.   

    rectInter2既属于B又属于A
    不对
      

  2.   

    CRect 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));
      

  3.   

    我是说rectIner既属于B又属于A
    我要求属于A
    不属于B
    的那一部分
      

  4.   

    你这问题怪呀,AB相交,那相交区肯定属于A呀。还用得着算吗?
      

  5.   

    在windows下面,矩形都是很规矩的,就是四条边都是平行于x或者y轴的,这样两个矩形相交,你得到相交矩形以后,他的4个顶点一定有4个(两个矩形一样)或者2个或者1个顶点在A内,然后你在判断到底一下,就可以根据在A内的顶点与A的顶点构造出你要求的矩形了。
    或者,你直接用这个函数吧
    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里面
      

  6.   

    呵呵,还没有看懂是什么问题,如果要有解,就是要求A-(A∩B)?
      

  7.   

    真是服了你,这样想
    假如有一个矩形Rect1,顶点是A,B,C,D,另外有一个矩形Rect2和他相交,相交后的矩形Rect3有一个顶点落在Rect1内,这个点是G,那么,这个点就把Rect1分成了4个小矩形,其中有一个是Rect3,那么另外3个就是你所要求的矩形了,对于有2个,4个顶点落在Rect1内的情况你可以自己分析
    想问题要自己多动动脑筋,在vc里面没有这样的函数,但是我们可以编程解决这个问题,如果还是不明白,给我写信吧[email protected]这样讨论的话方便一些