寸動 (Jog) 鈕:寸動運動

寸動運動使用兩個寸動鈕:向前寸動及向後寸動,鈕的行為可客製化,此範例使用方式如下:

因為不使用點擊行為,因此代碼未寫在 OnBnClicked 函式中,而是使用 PreTranslateMessage 來接收滑鼠事件,當按住滑鼠左鍵時,JogAxis 會用來將軸向前或向後寸動;當放開滑鼠鍵時,HaltAxis 則會用來停止寸動,而已轉換為雙精準浮點數字的指令速度會從 m_CMD_VEL 接收。

BOOL CMFC_GUIDlg::PreTranslateMessage(MSG* pMsg)
{
   if (pMsg->message == WM_LBUTTONDOWN)
   {
      if (pMsg->hwnd == GetDlgItem(IDC_BTN_JOG_F)->m_hWnd)
      {
         int Mindex = m_MotorList.GetCurSel();

         //Commands a never-ending controlled motion at a specified velocity.
         ::JogAxis(Mindex, double(m_CMD_VEL), 36000, 36000, 3600000, mcPositiveDirection);
      }
      if (pMsg->hwnd == GetDlgItem(IDC_BTN_JOG_B)->m_hWnd)
      {
         int Mindex = m_MotorList.GetCurSel();

         //Commands a never-ending controlled motion at a specified velocity.
         ::JogAxis(Mindex, double(m_CMD_VEL), 36000, 36000, 3600000, mcNegativeDirection);
      }
   }
   if (pMsg->message == WM_LBUTTONUP)
   {
      if (pMsg->hwnd == GetDlgItem(IDC_BTN_JOG_F)->m_hWnd)
      {
         int Mindex = m_MotorList.GetCurSel();

         //Commands a controlled motion stop.
         ::HaltAxis(Mindex, 3600, 360000, mcAborting);
      }
      if (pMsg->hwnd == GetDlgItem(IDC_BTN_JOG_B)->m_hWnd)
      {
         int Mindex = m_MotorList.GetCurSel();

         //Commands a controlled motion stop.
         ::HaltAxis(Mindex, 3600, 360000, mcAborting);
      }
   }
   return CDialog::PreTranslateMessage(pMsg);
}