诸位高手有谁能够给我提供一个SetWorldTransform用于画矩形旋转的例子,急需。另我看到网上很多人说自己定义矩形的4个点就可以画任意角度的矩形,可是我看了CRect的构造函数中没有通过4个点构造矩形的,最多用2个点构造,那如果我想画任意角度的矩形该怎么办呢?

解决方案 »

  1.   

    x' = -y*sin@ + x*cos@
    y' = x*sin@ + y*cos@
      

  2.   

            int nGraphicsMode = SetGraphicsMode(hDc, GM_ADVANCED);
            XFORM xform;
            if ( m_iAngle != 0 )
            {
                double fangle = (double)m_iAngle / 180. * 3.1415926;
                xform.eM11 = (float)cos(fangle);
                xform.eM12 = (float)sin(fangle);
                xform.eM21 = (float)-sin(fangle);
                xform.eM22 = (float)cos(fangle);
                xform.eDx = (float)(centerPt.x - cos(fangle)*centerPt.x + sin(fangle)*centerPt.y);
                xform.eDy = (float)(centerPt.y - cos(fangle)*centerPt.y - sin(fangle)*centerPt.x);            SetWorldTransform(hDc, &xform);
            }        Rectangle(hDc,centerPt.x - 20,centerPt.y - 30, centerPt.x + 20,centerPt.y + 30 );
    示例:http://www.codeproject.com/KB/GDI/setworldtransform%28%29.aspx