Programming/MFC [마우스] PreTranslateMessage 함수로 마우스 이벤트 처리 푸어맨 2017. 2. 23. 10:36 BOOL CPixelMakerDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if (pMsg->message == WM_LBUTTONDOWN) { SetTimer(TIMER_WM_LDRAG, 50, 0); } else if (pMsg->message == WM_LBUTTONUP) { KillTimer(TIMER_WM_LDRAG); } else if (pMsg->message == WM_RBUTTONDOWN) { SetTimer(TIMER_WM_RDRAG, 50, 0); } else if (pMsg->message == WM_RBUTTONUP) { KillTimer(TIMER_WM_RDRAG); } return CDialogEx::PreTranslateMessage(pMsg); } int CPixelMakerDlg::GetCheckboxIdx(void) { POINT pt; CPoint point; int x, y, idx; GetCursorPos(&point); ScreenToClient(&point); if ((m_ptMin.x <= point.x) && (point.x <= m_ptMax.x)) { if ((m_ptMin.y <= point.y) && (point.y <= m_ptMax.y)) { x = (point.x - m_ptMin.x) / m_szCheckbox.cx; y = (point.y - m_ptMin.y) / m_szCheckbox.cy; idx = x + PIXEL_WIDTH * y; return idx; } } return -1; } void CPixelMakerDlg::OnTimer(UINT_PTR nIDEvent) { // TODO: Add your message handler code here and/or call default int idx; switch (nIDEvent) { case TIMER_WM_LDRAG: idx = GetCheckboxIdx(); if ((idx >= 0) && (idx < PIXEL_WIDTH*PIXEL_HEIGHT)) { m_check[idx].SetCheck(1); } break; case TIMER_WM_RDRAG: idx = GetCheckboxIdx(); if ((idx >= 0) && (idx < PIXEL_WIDTH*PIXEL_HEIGHT)) { m_check[idx].SetCheck(0); } break; default: break; } CDialogEx::OnTimer(nIDEvent); }