本文转载连接: http://buaagc.lofter.com/post/1cd54dda_b61e206
BOOL CDlgMove::PreTranslateMessage(MSG* pMsg)
{
CSingleton* pInfo = CSingleton::GetInstance();
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == VK_ESCAPE )
return TRUE;
int iAxis = 1;
if (m_bLeft)
iAxis += 2;
if (pMsg->wParam == 'A' && GetKeyState(VK_SHIFT) < 0 && m_bSingle == false) //按下shift和A键
{
m_bSingle = true;
if (((CButton*)GetDlgItem(IDC_RADIO3))->GetCheck() == BST_CHECKED) //jog运动
{
TJogPrm jog;
GT_PrfJog(iAxis); // 读取Jog运动参数
GT_GetJogPrm(iAxis, &jog);
jog.acc = 0.3;
GT_SetJogPrm(iAxis, &jog); // 设置Jog运动参数
if (m_bLeft)
GT_SetVel(iAxis, pInfo->_iVel); // 设置AXIS轴的目标速度
else
GT_SetVel(iAxis, -1*pInfo->_iVel);
GT_Update(1<<(iAxis - 1)); // 启动AXIS轴的运动
}
else
{
TTrapPrm trap;
GT_PrfTrap(iAxis);
GT_GetTrapPrm(iAxis, &trap); // 读取点位运动参数
trap.acc = 0.3;
trap.smoothTime = 25;
GT_SetTrapPrm(iAxis, &trap);
DOUBLE fCurrPos;
GT_GetAxisEncPos(iAxis,&fCurrPos);
CString strMM;
GetDlgItemText(IDC_EDIT_P,strMM);
int iAdd = atof(strMM)*m_fPC;
GT_SetPos(iAxis,(long)(fCurrPos + abs(iAdd)));
GT_SetVel(iAxis, pInfo->_iVel);
GT_Update(1<<(iAxis -1));
}
}
if (pMsg->wParam == 'D' && GetKeyState(VK_SHIFT) < 0 && m_bSingle == false)
{
m_bSingle = true;
if (((CButton*)GetDlgItem(IDC_RADIO3))->GetCheck() == BST_CHECKED) //jog运动
{
TJogPrm jog;
GT_PrfJog(iAxis); // 读取Jog运动参数
GT_GetJogPrm(iAxis, &jog);
jog.acc = 0.3;
GT_SetJogPrm(iAxis, &jog); // 设置Jog运动参数
if (m_bLeft)
GT_SetVel(iAxis, -1*pInfo->_iVel);
else
GT_SetVel(iAxis, pInfo->_iVel); // 设置AXIS轴的目标速度
GT_Update(1<<(iAxis - 1)); // 启动AXIS轴的运动
}
else
{
TTrapPrm trap;
GT_PrfTrap(iAxis);
GT_GetTrapPrm(iAxis, &trap); // 读取点位运动参数
trap.acc = 0.3;
trap.smoothTime = 25;
GT_SetTrapPrm(iAxis, &trap);
DOUBLE fCurrPos;
GT_GetAxisEncPos(iAxis,&fCurrPos);
CString strMM;
GetDlgItemText(IDC_EDIT_P,strMM);
int iAdd = atof(strMM)*m_fPC;
GT_SetPos(iAxis,(long)(fCurrPos - abs(iAdd)));
GT_SetVel(iAxis, pInfo->_iVel);
GT_Update(1<<(iAxis -1));
}
}
if (pMsg->wParam == 'W' && GetKeyState(VK_SHIFT) < 0 && m_bSingle == false)
{
m_bSingle = true;
iAxis++;
if (((CButton*)GetDlgItem(IDC_RADIO3))->GetCheck() == BST_CHECKED) //jog运动
{
TJogPrm jog;
GT_PrfJog(iAxis); // 读取Jog运动参数
GT_GetJogPrm(iAxis, &jog);
jog.acc = 0.3;
GT_SetJogPrm(iAxis, &jog); // 设置Jog运动参数
GT_SetVel(iAxis, pInfo->_iVel); // 设置AXIS轴的目标速度
GT_Update(1<<(iAxis - 1)); // 启动AXIS轴的运动
}
else
{
TTrapPrm trap;
double prfPos;
GT_PrfTrap(iAxis);
GT_GetTrapPrm(iAxis, &trap); // 读取点位运动参数
trap.acc = 0.3;
trap.smoothTime = 25;
GT_SetTrapPrm(iAxis, &trap);
DOUBLE fCurrPos;
GT_GetAxisEncPos(iAxis,&fCurrPos);
CString strMM;
GetDlgItemText(IDC_EDIT_P,strMM);
int iAdd = atof(strMM)*m_fPC;
GT_SetPos(iAxis,(long)(fCurrPos + abs(iAdd)));
GT_SetVel(iAxis, pInfo->_iVel);
GT_Update(1<<(iAxis -1));
}
}
if (pMsg->wParam == 'S' && GetKeyState(VK_SHIFT) < 0 && m_bSingle == false)
{
m_bSingle = true;
iAxis++;
if (((CButton*)GetDlgItem(IDC_RADIO3))->GetCheck() == BST_CHECKED) //jog运动
{
TJogPrm jog;
GT_PrfJog(iAxis); // 读取Jog运动参数
GT_GetJogPrm(iAxis, &jog);
jog.acc = 0.3;
GT_SetJogPrm(iAxis, &jog); // 设置Jog运动参数
GT_SetVel(iAxis, -1*pInfo->_iVel); // 设置AXIS轴的目标速度
GT_Update(1<<(iAxis - 1)); // 启动AXIS轴的运动
}
else
{
TTrapPrm trap;
GT_PrfTrap(iAxis);
GT_GetTrapPrm(iAxis, &trap); // 读取点位运动参数
trap.acc = 0.3;
trap.smoothTime = 25;
GT_SetTrapPrm(iAxis, &trap);
DOUBLE fCurrPos;
GT_GetAxisEncPos(iAxis,&fCurrPos);
CString strMM;
GetDlgItemText(IDC_EDIT_P,strMM);
int iAdd = atof(strMM)*m_fPC;
GT_SetPos(iAxis,(long)(fCurrPos - abs(iAdd)));
GT_SetVel(iAxis, pInfo->_iVel);
GT_Update(1<<(iAxis -1));
}
}
}
if (pMsg->message == WM_KEYUP)
{
if (pMsg->wParam == 'A' || pMsg->wParam == 'D' || pMsg->wParam == 'W' || pMsg->wParam == 'S')
{
m_bSingle = false;
int iAxis = 1;
if (m_bLeft)
iAxis += 2;
if (pMsg->wParam == 'W' || pMsg->wParam == 'S')
iAxis++;
if (((CButton*)GetDlgItem(IDC_RADIO3))->GetCheck() == BST_CHECKED)
{
for (int i = 0;i < 4;i++)
GT_Stop(1<
}
}
}
return CDialogEx::PreTranslateMessage(pMsg);
}