AnnMouseDown example for C++ 4.0 and later
Note: This topic is for Document/Medical only.
void CAnntestDlg::OnAnnMouseDownLeadctrl1(short Button, short Shift, long x, long y)
{
m_x0 = x;
m_y0 = y;
switch(m_LEAD1.GetAnnTool())
{
case ANNTOOL_USER_FIRST:
// create the objects
m_LEAD1.AnnSetSelected(m_LEAD1.GetAnnContainer(), FALSE, TRUE);
//Add an undo node to undo the creation of these objects.
m_LEAD1.AnnAddUndoNode();
m_hRectObject = m_LEAD1.AnnCreate(ANNOBJECT_RECT, TRUE, TRUE);
m_hEllipseObject = m_LEAD1.AnnCreate(ANNOBJECT_ELLIPSE, TRUE, TRUE);
// set the automation defaults to the objects newly created
m_LEAD1.AnnSetAutoDefaults(m_hRectObject, 0);
m_LEAD1.AnnSetAutoDefaults(m_hEllipseObject, 0);
// start defining them from the x, y coordinate
m_LEAD1.AnnDefine(m_hRectObject, (float)x, (float)y, ANNDEFINE_BEGINSET);
m_LEAD1.AnnDefine(m_hEllipseObject, (float)x, (float)y, ANNDEFINE_BEGINSET);
break;
}
}
void CAnntestDlg::OnAnnMouseMoveLeadctrl1(short Button, short Shift, long x, long y)
{
if(Button == 1)
{
switch(m_LEAD1.GetAnnTool())
{
case ANNTOOL_USER_FIRST:
// update the objects from the x, y coordinate
m_LEAD1.AnnDefine(m_hRectObject, (float)x, (float)y, ANNDEFINE_UPDATE);
m_LEAD1.AnnDefine(m_hEllipseObject, (float)x, (float)y, ANNDEFINE_UPDATE);
break;
case ANNTOOL_RECT:
AdjustMousePos(Shift, x, y);
break;
}
}
}
void CAnntestDlg::OnAnnMouseUpLeadctrl1(short Button, short Shift, long x, long y)
{
switch(m_LEAD1.GetAnnTool())
{
case ANNTOOL_USER_FIRST:
m_LEAD1.AnnDefine(m_hRectObject, (float)x, (float)y, ANNDEFINE_END);
m_LEAD1.AnnDefine(m_hEllipseObject, (float)x, (float)y, ANNDEFINE_END);
m_LEAD1.AnnSetSelected(m_hRectObject, TRUE, FALSE);
m_LEAD1.AnnSetSelected(m_hEllipseObject, TRUE, FALSE);
m_LEAD1.AnnGroup(m_LEAD1.GetAnnContainer(), ANNFLAG_RECURSE |
ANNFLAG_SELECTED, "");
m_hEllipseObject = 0;
m_hRectObject = 0;
break;
case ANNTOOL_RECT:
AdjustMousePos(Shift, x, y);
break;
}
}
void CAnntestDlg::AdjustMousePos(short Shift, long x, long y)
{
long dx,dy;
if(Shift == 1)
{
// if shift key is down, force the creation of squares
dx = abs(x - m_x0);
dy = abs(y - m_y0);
if(dx > dy)
{
// adjust y to be as far from y0 as x is from x0
if(y > m_y0)
y = m_y0 + dx;
else
y = m_y0 - dx;
}
else
{
// adjust x to be as far from x0 as y is from y0
if(x > m_x0)
x = m_x0 + dy;
else
x = m_x0 - dy;
}
// set the mouse cursor and update its position
m_LEAD1.SetMousePos((float)x, (float)y, FALSE);
}
}