본문 바로가기
Development Solutions/MFC

[MFC][1] To save click coordinates using a CList class (CList 클래스를 이용한 클릭 좌표 저장하기)

by Dev Diary Hub 2022. 8. 20.
반응형

[MFC][1]

To save click coordinates using a CList class

CList 클래스를 이용한 클릭 좌표 저장하기

 

(추천) Qt QML과 C++로 시작하는 크로스플랫폼 앱 개발 강의 - 입문편

https://inf.run/3XmSH

 

Qt QML과 C++로 시작하는 크로스플랫폼 앱 개발 - 입문편 강의 - 인프런

Qt QML과 C++를 사용하여 크로스플랫폼 애플리케이션 개발에 입문할 수 있습니다. 해당 강의에서는 윈도우 응용 프로그램 타겟으로 개발을 진행합니다., 강의 주제 📖 이 강의를 통해 참가자들은

www.inflearn.com

 

 

 

왼쪽 마우스 클릭한 경우 클릭한 위치와 시간 간격을 알림 창으로 출력하고,

오른쪽 마우스 클릭한 경우 왼쪽 마우스로 클릭한 총 클릭횟수와 저장된 클릭 위치를 출력하도록 했습니다.

 

또한 왼쪽 마우스를 한번도 클릭하지 않은 경우 안내 메시지를 띄우도록 했습니다.

(학번에 해당하는 텍스트는 "프로젝트 이름"으로 바꿨으니 양해바랍니다.)

 

(If you click the left mouse, output the location and time interval that you clicked to the notification window

If you click the right mouse, you can print out the total number of clicks you click with the left mouse and the saved click location.



Also, if you've never clicked the left mouse, you've been prompted.

(Please understand that the text corresponding to the class number has been changed to "Project Name".))

 

 

 

 

-ChildView.cpp

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
 
// ChildView.cpp : CChildView 클래스의 구현
//
 
#include "stdafx.h"
#include "프로젝트이름.h"
#include "ChildView.h"
 
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
 
 
// CChildView
 
CChildView::CChildView()
{
    cnt = 0// 왼쪽 클릭 횟수를 카운트
}
 
CChildView::~CChildView()
{
    m_list.RemoveAll(); // 소멸자를 통해 이중연결리스트 m_list메모리 반환
}
 
 
BEGIN_MESSAGE_MAP(CChildView, CWnd)
    ON_WM_PAINT()
    ON_WM_RBUTTONDOWN()
    ON_WM_LBUTTONDOWN()
    ON_WM_SIZE()
END_MESSAGE_MAP()
 
 
 
// CChildView 메시지 처리기
 
BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
{
    if (!CWnd::PreCreateWindow(cs))
        return FALSE;
 
    cs.dwExStyle |= WS_EX_CLIENTEDGE;
    cs.style &= ~WS_BORDER;
    cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS,
        ::LoadCursor(NULL, IDC_ARROW), reinterpret_cast<HBRUSH>(COLOR_WINDOW + 1), NULL);
 
    return TRUE;
}
 
void CChildView::OnPaint()
{
    CPaintDC dc(this); // 그리기를 위한 디바이스 컨텍스트입니다.
 
    // TODO: 여기에 메시지 처리기 코드를 추가합니다.
 
    // 그리기 메시지에 대해서는 CWnd::OnPaint()를 호출하지 마십시오.
 
    CString str;
    str.Format(_T("윈도우크기 width: %d, height: %d"), m_pt.x, m_pt.y);
 
    dc.TextOutW(m_pt.x / 2, m_pt.y / 2, str);
}
 
 
void CChildView::OnLButtonDown(UINT nFlags, CPoint point)
{
    // TODO: 여기에 메시지 처리기 코드를 추가 및/또는 기본값을 호출합니다.
 
    start = CTime::GetCurrentTime();
    CTimeSpan tm = start - end;
    end = start;
 
    m_list.AddTail(point);
    cnt++;
 
    if (cnt == 1// 왼쪽버튼을 한번도 클릭하지 않았을 때, 시간간격=0초
    {
        tm = 0;
    }
    CString str;
    str.Format(_T("왼쪽클릭 위치 (%d, %d)\n왼쪽클릭 간격: %d초\n"), point.x, point.y, tm);
 
    MessageBox(str, _T("왼쪽클릭"));
 
    CWnd::OnLButtonDown(nFlags, point);
}
 
 
void CChildView::OnRButtonDown(UINT nFlags, CPoint point)
{
    // TODO: 여기에 메시지 처리기 코드를 추가 및/또는 기본값을 호출합니다.
 
    if (cnt == 0// 한번도 왼쪽클릭을 하지 않았을 때
    {
        CString str;
        str.Format(_T("왼쪽클릭 1번 이상 해야 함"));
        MessageBox(str, _T("왼쪽클릭 경고"));
    }
    else // 1번 이상 했을 때
    {
        POSITION pos = m_list.GetHeadPosition();
 
        CString str;
        str.Format(_T("왼쪽클릭수: %d\n \n클릭위치:\n"), cnt);
 
        while (pos != NULL// 리스트를 Head 노드부터 마지막 노드까지 순회
        {
            CPoint p = m_list.GetNext(pos);
 
            CString str1;
            str1.Format(_T("(%d, %d)\n"), p.x, p.y);
            str += str1;
        }
 
        MessageBox(str, _T("오른쪽클릭"));
    }
 
    CWnd::OnRButtonDown(nFlags, point);
}
 
 
void CChildView::OnSize(UINT nType, int cx, int cy)
{
    CWnd::OnSize(nType, cx, cy);
 
    // TODO: 여기에 메시지 처리기 코드를 추가합니다.
 
    // 윈도우 사이즈를 멤버변수로 받음
    m_pt.x = cx;
    m_pt.y = cy;
}
 
cs
반응형

- ChildView.h

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 
// ChildView.h : CChildView 클래스의 인터페이스
//
 
#include <afxtempl.h>
#pragma once
 
 
// CChildView 창
 
class CChildView : public CWnd
{
    // 생성입니다.
public:
    CChildView();
 
    // 특성입니다.
public:
    int cnt;
    CList <CPoint, CPoint&> m_list;
    CTime start, end;
    CPoint m_pt;
 
    // 작업입니다.
public:
 
    // 재정의입니다.
protected:
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
 
    // 구현입니다.
public:
    virtual ~CChildView();
 
    // 생성된 메시지 맵 함수
protected:
    afx_msg void OnPaint();
    DECLARE_MESSAGE_MAP()
public:
    afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    afx_msg void OnSize(UINT nType, int cx, int cy);
};
 
 
cs

 



 

(추천) Qt QML과 C++로 시작하는 크로스플랫폼 앱 개발 강의 - 입문편

https://inf.run/3XmSH

 

Qt QML과 C++로 시작하는 크로스플랫폼 앱 개발 - 입문편 강의 - 인프런

Qt QML과 C++를 사용하여 크로스플랫폼 애플리케이션 개발에 입문할 수 있습니다. 해당 강의에서는 윈도우 응용 프로그램 타겟으로 개발을 진행합니다., 강의 주제 📖 이 강의를 통해 참가자들은

www.inflearn.com

 

반응형