if( IsSelected())
{
UINT iTopLeft_BottomRight_Cursor = 0;
UINT iMidTop_MidBottom_Cursor = 0;
UINT iTopRight_BottomLeft_Cursor = 0;
UINT iMidLeft_MidRight_Cursor = 0;
float fRotationAngle = 0.0f;
GetRotationAngleForFrame(GetCurrentFrame(), fRotationAngle);
int nRotAngle = Round(fRotationAngle * (180.0f/PI));
}
if (
( (nRotAngle > 0) && (nRotAngle < 23 ) )
|| ( (nRotAngle > 180) && (nRotAngle < 203) )
|| ( (nRotAngle > 270) && (nRotAngle < 293) )
|| ( (nRotAngle > 90 ) && (nRotAngle < 113) )
)
{
iTopLeft_BottomRight_Cursor = CURSOR_NESW;
iMidTop_MidBottom_Cursor = CURSOR_EW;
iTopRight_BottomLeft_Cursor = CURSOR_NWSE;
iMidLeft_MidRight_Cursor = CURSOR_NS;
}
else if (
(nRotAngle > 337)
|| (nRotAngle > 157 && nRotAngle <= 180)
|| (nRotAngle == 0 )
|| (nRotAngle > 67 && nRotAngle < 91)
|| (nRotAngle > 247 && nRotAngle <= 270)
)
{
iTopLeft_BottomRight_Cursor = CURSOR_NWSE;
iMidTop_MidBottom_Cursor = CURSOR_NS;
iTopRight_BottomLeft_Cursor = CURSOR_NESW;
iMidLeft_MidRight_Cursor = CURSOR_EW;
}
else if (
(nRotAngle > 22 && nRotAngle < 68)
|| (nRotAngle > 202 && nRotAngle < 248)
|| (nRotAngle > 112 && nRotAngle < 158)
|| (nRotAngle > 292 && nRotAngle < 338)
)
{
iTopLeft_BottomRight_Cursor = CURSOR_EW;
iMidTop_MidBottom_Cursor = CURSOR_NWSE;
iTopRight_BottomLeft_Cursor = CURSOR_NS;
iMidLeft_MidRight_Cursor = CURSOR_NESW;
}
UpdateHandlesWhenHover();
if (m_TopLeftRect.PtInRect(pt) || m_BottomRightRect.PtInRect(pt) )
{
if(hCursor)
{
DestroyIcon(hCursor);
hCursor = NULL;
}
hCursor = GetCustomCursor(AfxGetInstanceHandle(), iTopLeft_BottomRight_Cursor, _T("PNG"));
}
else if (m_MidTopRect.PtInRect(pt) || m_MidBottomRect.PtInRect(pt))
{
if(hCursor)
{
DestroyIcon(hCursor);
hCursor = NULL;
}
hCursor = GetCustomCursor(AfxGetInstanceHandle(), iMidTop_MidBottom_Cursor, _T("PNG"));
}
else if (m_TopRightRect.PtInRect(pt) || m_BottomLeftRect.PtInRect(pt))
{
if(hCursor)
{
DestroyIcon(hCursor);
hCursor = NULL;
}
hCursor = GetCustomCursor(AfxGetInstanceHandle(), iTopRight_BottomLeft_Cursor, _T("PNG"));
}
else if (m_MidLeftRect.PtInRect(pt) || m_MidRightRect.PtInRect(pt) )
{
if(hCursor)
{
DestroyIcon(hCursor);
hCursor = NULL;
}
hCursor = GetCustomCursor(AfxGetInstanceHandle(), iMidLeft_MidRight_Cursor, _T("PNG"));
}
else if(IsPtWithinROI(pt))
{
if(hCursor)
{
DestroyIcon(hCursor);
hCursor = NULL;
}
hCursor = GetCustomCursor(AfxGetInstanceHandle(), IDR_MOVE_CURSOR, _T("PNG"));
break;
}
else
{
if(hCursor)
{
DestroyIcon(hCursor);
hCursor = NULL;
}
hCursor = GetCustomCursor(AfxGetInstanceHandle(), IDR_ARROW_CURSOR, _T("PNG"));
}
}
break;
}
case CURSOR_ON_REGION:
{
if(hCursor)
{
DestroyIcon(hCursor);
hCursor = NULL;
}
hCursor = GetCustomCursor(AfxGetInstanceHandle(), IDR_MOVE_CURSOR, _T("PNG"));
break;
}
case CURSOR_ON_ROTATION_HANDLE:
{
if(hCursor)
{
DestroyIcon(hCursor);
hCursor = NULL;
}
hCursor = GetCustomCursor(AfxGetInstanceHandle(), IDR_ROTATION_MARK_CURSOR, _T("PNG"));
break;
}
case CURSOR_ROTATING_REGION:
{
if(hCursor)
{
DestroyIcon(hCursor);
hCursor = NULL;
}
hCursor = GetCustomCursor(AfxGetInstanceHandle(), IDR_ROTATING_MARK_CURSOR, _T("PNG"));
break;
}
default:
{
if(hCursor)
{
DestroyIcon(hCursor);
hCursor = NULL;
}
hCursor = GetCustomCursor(AfxGetInstanceHandle(), IDR_ARROW_CURSOR, _T("PNG"));
break;
}
}
pmainDlg->m_hCursor = hCursor;
SetCursor(pmainDlg->m_hCursor);
UpdateHandlesWhenHover()
{
CShapeCal cShapeCal;
CRect rcMeasRect(0,0,100,100);
CBaseMeasCal cBaseMeasCal;
CPrecisionPoint ptCenter;
CList<CPrecisionPoint,CPrecisionPoint&> ptInputList;
CPrecisionPoint ptPoint;
ptPoint = m_TopLeftRect.CenterPoint();
ptInputList.AddTail(ptPoint);
ptPoint = m_MidLeftRect.CenterPoint();
ptInputList.AddTail(ptPoint);
ptPoint = m_BottomLeftRect.CenterPoint();
ptInputList.AddTail(ptPoint);
ptPoint = m_MidTopRect.CenterPoint();
ptInputList.AddTail(ptPoint);
ptPoint = m_MidBottomRect.CenterPoint();
ptInputList.AddTail(ptPoint);
ptPoint = m_TopRightRect.CenterPoint();
ptInputList.AddTail(ptPoint);
ptPoint = m_MidRightRect.CenterPoint();
ptInputList.AddTail(ptPoint);
ptPoint = m_BottomRightRect.CenterPoint();
ptInputList.AddTail(ptPoint);
cBaseMeasCal.CalculateCenterPoint(ptInputList,ptCenter);
CList<CPrecisionPoint,CPrecisionPoint&> ptOutputList;
double dReturn = 0.0;
dReturn = cShapeCal.SortEditPoint(rcMeasRect,ptInputList,ptCenter,ptOutputList);
CPrecisionPoint ptTopLeft(-1,-1);
vector<CPoint> vectHandles;
vectHandles.push_back(CPoint(m_TopLeftRect.CenterPoint()));
vectHandles.push_back(CPoint(m_MidLeftRect.CenterPoint()));
vectHandles.push_back(CPoint(m_BottomLeftRect.CenterPoint()));
vectHandles.push_back(CPoint(m_MidTopRect.CenterPoint()));
vectHandles.push_back(CPoint(m_MidBottomRect.CenterPoint()));
vectHandles.push_back(CPoint(m_TopRightRect.CenterPoint()));
vectHandles.push_back(CPoint(m_MidRightRect.CenterPoint()));
vectHandles.push_back(CPoint(m_BottomRightRect.CenterPoint()));
::sort(vectHandles.begin(), vectHandles.end(), SortingFunction());
ptTopLeft = vectHandles[0];
POSITION position = ptOutputList.GetHeadPosition();
while( position != NULL )
{
ptPoint = ptOutputList.GetNext(position);
if(ptTopLeft == ptPoint)
{
m_TopLeftRect.SetRect(ptPoint.x,ptPoint.y,ptPoint.x,ptPoint.y);
m_TopLeftRect.InflateRect(ROI_HANDLE_MARGIN,ROI_HANDLE_MARGIN);
if( position == NULL )
{
position = ptOutputList.GetHeadPosition();
}
ptPoint = ptOutputList.GetNext(position);
m_MidTopRect.SetRect(ptPoint.x,ptPoint.y,ptPoint.x,ptPoint.y);
m_MidTopRect.InflateRect(ROI_HANDLE_MARGIN,ROI_HANDLE_MARGIN);
if( position == NULL )
{
position = ptOutputList.GetHeadPosition();
}
ptPoint = ptOutputList.GetNext(position);
m_TopRightRect.SetRect(ptPoint.x,ptPoint.y,ptPoint.x,ptPoint.y);
m_TopRightRect.InflateRect(ROI_HANDLE_MARGIN,ROI_HANDLE_MARGIN);
if( position == NULL )
{
position = ptOutputList.GetHeadPosition();
}
ptPoint = ptOutputList.GetNext(position);
m_MidRightRect.SetRect(ptPoint.x,ptPoint.y,ptPoint.x,ptPoint.y);
m_MidRightRect.InflateRect(ROI_HANDLE_MARGIN,ROI_HANDLE_MARGIN);
if( position == NULL )
{
position = ptOutputList.GetHeadPosition();
}
ptPoint = ptOutputList.GetNext(position);
m_BottomRightRect.SetRect(ptPoint.x,ptPoint.y,ptPoint.x,ptPoint.y);
m_BottomRightRect.InflateRect(ROI_HANDLE_MARGIN,ROI_HANDLE_MARGIN);
if( position == NULL )
{
position = ptOutputList.GetHeadPosition();
}
ptPoint = ptOutputList.GetNext(position);
m_MidBottomRect.SetRect(ptPoint.x,ptPoint.y,ptPoint.x,ptPoint.y);
m_MidBottomRect.InflateRect(ROI_HANDLE_MARGIN,ROI_HANDLE_MARGIN);
if( position == NULL )
{
position = ptOutputList.GetHeadPosition();
}
ptPoint = ptOutputList.GetNext(position);
m_BottomLeftRect.SetRect(ptPoint.x,ptPoint.y,ptPoint.x,ptPoint.y);
m_BottomLeftRect.InflateRect(ROI_HANDLE_MARGIN,ROI_HANDLE_MARGIN);
if( position == NULL )
{
position = ptOutputList.GetHeadPosition();
}
ptPoint = ptOutputList.GetNext(position);
m_MidLeftRect.SetRect(ptPoint.x,ptPoint.y,ptPoint.x,ptPoint.y);
m_MidLeftRect.InflateRect(ROI_HANDLE_MARGIN,ROI_HANDLE_MARGIN);
break;
}
}
}
struct SortingFunction
{
bool operator()(const CRect& a, const CRect& b)
{
if (a.left == b.left)
return a.top <= b.top;
else
return a.left < b.left;
}
bool operator()(const CPoint& a, const CPoint& b)
{
if (a.x == b.x)
return a.y <= b.y;
else
return a.x < b.x;
}
};</pre>