네모상자를 하나 만들어서 클릭했을 경우 마우스를 따라서 움직이게 만들어보자
void CChildView::OnPaint()
{
CPaintDC dc(this);
dc.Rectangle(m_Rect);
}
void CChildView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_pos = point;
if( PtInRect(m_Rect, m_pos) ){
m_bClick = true;
SetCapture();//캡처를 사용해서 윈도우 작업영역을 벗어나도 작업하게 해준다.
}
CWnd::OnLButtonDown(nFlags, point);
}
void CChildView::OnLButtonUp(UINT nFlags, CPoint point)
{
m_bClick = false;
ReleaseCapture();//캡처를 풀어준다
CWnd::OnLButtonUp(nFlags, point);
}
void CChildView::OnMouseMove(UINT nFlags, CPoint point)
{
if( m_bClick ){
m_Rect.top -= m_pos.y - point.y;
m_Rect.left -= m_pos.x - point.x;
m_Rect.right -= m_pos.x - point.x;
m_Rect.bottom -= m_pos.y - point.y;
Invalidate(true);
m_pos = point;//이게 없으면 쭉 날아가 버림.
}
CWnd::OnMouseMove(nFlags, point);
}
결과 동영상
마우스 움직이는게 보이지 않아서 움직일때 좌표가 보이게 해놨다.
'Programming > Blah Blah' 카테고리의 다른 글
크롬 번역 아이콘 복구 (0) | 2015.08.22 |
---|---|
PHP 대충 써보기 (0) | 2015.08.21 |
PHP array함수 (0) | 2015.08.19 |
문자열 에러 char* 에서 lpcwstr으로 변환 할 수 없습니다. (0) | 2015.08.16 |
WinMain (0) | 2015.06.02 |
afxcontrolbars.h 포함 파일을 찾을수 없습니다. (0) | 2015.05.27 |
MFC 4대 클래스 (0) | 2015.05.11 |
API로 만든DNF (0) | 2015.05.09 |