[MFC] Mouse Message 처리

Posted by seunggwon
2008. 10. 30. 19:29 IT Note/기타언어

오른쪽 마우스를 눌렀을 때, 현재 마우스 위치 출력
1. Single Document (SDI)로 작성
2. WM_RBUTTONDOWN와 WM_LBUTTONDOWN에 대한 메시지 핸들러 추가(class wizard 이용)
3. CWnd::MessageBox를 이용하여, 현재의 마우스 위치를 출력한다.
4. ::wsprintf, CString::Format 사용

아래의 소스를 추가한다.
void CMessageView::OnRButtonDown(UINT nFlags, CPoint point)
{
 char buf[20];
 wsprintf(buf,"X:%4d,Y:%4d",point.x,point.y);
 MessageBox(buf,"마우스 위치",MB_OK|MB_ICONINFORMATION);

 CView::OnRButtonDown(nFlags, point);
}

void CMessageView::OnLButtonDown(UINT nFlags, CPoint point)
{
 CString Str;
 Str.Format("x:%4d,Y:%4d",point.x,point.y);
 MessageBox(Str,"마우스 위치",MB_OK|MB_ICONINFORMATION);

 CView::OnLButtonDown(nFlags, point);
}

출력결과(마우스 오른쪽 버튼과 왼쪽 버튼을 눌렀을 경우)

'IT Note > 기타언어' 카테고리의 다른 글

[MFC] Keyboard Message 처리  (0) 2008.10.30
[MFC] Dialog based Program  (0) 2008.10.23
[MFC] MFC 소개  (0) 2008.10.23