본문 바로가기
Development Solutions/MFC

[MFC][3] Developing Paint (그림판 개발하기)

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

[MFC][3] 

Developing Paint

그림판 만들기

 

 

2022.08.20 - [Development Solutions/MFC] - [MFC][2] Declare classes to shape and clear (클래스 선언하여 도형 그리고 지우기)

 

[MFC][2] Declare classes to shape and clear (클래스 선언하여 도형 그리고 지우기)

[MFC][2] Declare classes to shape and clear 클래스 선언하여 도형 그리고 지우기 2022.08.20 - [Development Solutions/MFC] - [MFC][1] To save click coordinates using a CList class (CList 클래스를..

studiodoc.tistory.com

 

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

https://inf.run/3XmSH

 

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

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

www.inflearn.com

 

 

직선, 사각형, 타원, 텍스트, 다각형의 도형과 그에 대한 펜 색상, 브러쉬 색상, 폰트 색상을 설정할 수 있도록 하는 그림판을 구현했습니다.

 

화살키 키보드 입력으로 위치(상,하,좌,우)와 크기 조정(상,하)도 가능하며 직렬화를 이용한 저장 및 열기 기능도 구현했습니다.

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

 

(Implemented a drawing board that allows you to set up straight, square, oval, text, polygonal shapes, and pen, brush, and font colors for them.



Arrow key keyboard input can be used to position (up, down, left, right) and resize (up, down), and also to store and open using serialization.

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

 

 

- Doc.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
 
// hw3_프로젝트 이름Doc.cpp : Chw3_프로젝트 이름Doc 클래스의 구현
//
 
#include "stdafx.h"
// SHARED_HANDLERS는 미리 보기, 축소판 그림 및 검색 필터 처리기를 구현하는 ATL 프로젝트에서 정의할 수 있으며
// 해당 프로젝트와 문서 코드를 공유하도록 해 줍니다.
#ifndef SHARED_HANDLERS
#include "hw3_프로젝트 이름.h"
#endif
 
#include "hw3_프로젝트 이름Doc.h"
 
#include <propkey.h>
 
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
 
// Chw3_프로젝트 이름Doc
 
IMPLEMENT_DYNCREATE(Chw3_프로젝트 이름Doc, CDocument)
 
BEGIN_MESSAGE_MAP(Chw3_프로젝트 이름Doc, CDocument)
    ON_COMMAND(ID_LINE, &Chw3_프로젝트 이름Doc::OnLine)
    ON_UPDATE_COMMAND_UI(ID_LINE, &Chw3_프로젝트 이름Doc::OnUpdateLine)
    ON_COMMAND(ID_RECT, &Chw3_프로젝트 이름Doc::OnRect)
    ON_UPDATE_COMMAND_UI(ID_RECT, &Chw3_프로젝트 이름Doc::OnUpdateRect)
    ON_COMMAND(ID_ELLIPSE, &Chw3_프로젝트 이름Doc::OnEllipse)
    ON_UPDATE_COMMAND_UI(ID_ELLIPSE, &Chw3_프로젝트 이름Doc::OnUpdateEllipse)
    ON_COMMAND(ID_TEXT, &Chw3_프로젝트 이름Doc::OnText)
    ON_UPDATE_COMMAND_UI(ID_TEXT, &Chw3_프로젝트 이름Doc::OnUpdateText)
    ON_COMMAND(ID_BRUSH_RED, &Chw3_프로젝트 이름Doc::OnBrushRed)
    ON_UPDATE_COMMAND_UI(ID_BRUSH_RED, &Chw3_프로젝트 이름Doc::OnUpdateBrushRed)
    ON_COMMAND(ID_BRUSH_GREEN, &Chw3_프로젝트 이름Doc::OnBrushGreen)
    ON_COMMAND(ID_BRUSH_BLUE, &Chw3_프로젝트 이름Doc::OnBrushBlue)
    ON_UPDATE_COMMAND_UI(ID_BRUSH_GREEN, &Chw3_프로젝트 이름Doc::OnUpdateBrushGreen)
    ON_UPDATE_COMMAND_UI(ID_BRUSH_BLUE, &Chw3_프로젝트 이름Doc::OnUpdateBrushBlue)
    ON_COMMAND(ID_PEN_RED, &Chw3_프로젝트 이름Doc::OnPenRed)
    ON_UPDATE_COMMAND_UI(ID_PEN_RED, &Chw3_프로젝트 이름Doc::OnUpdatePenRed)
    ON_COMMAND(ID_PEN_GREEN, &Chw3_프로젝트 이름Doc::OnPenGreen)
    ON_UPDATE_COMMAND_UI(ID_PEN_GREEN, &Chw3_프로젝트 이름Doc::OnUpdatePenGreen)
    ON_COMMAND(ID_PEN_BLUE, &Chw3_프로젝트 이름Doc::OnPenBlue)
    ON_COMMAND(ID_FONT_RED, &Chw3_프로젝트 이름Doc::OnFontRed)
    ON_UPDATE_COMMAND_UI(ID_FONT_RED, &Chw3_프로젝트 이름Doc::OnUpdateFontRed)
    ON_COMMAND(ID_FONT_GREEN, &Chw3_프로젝트 이름Doc::OnFontGreen)
    ON_UPDATE_COMMAND_UI(ID_FONT_GREEN, &Chw3_프로젝트 이름Doc::OnUpdateFontGreen)
    ON_COMMAND(ID_FONT_BLUE, &Chw3_프로젝트 이름Doc::OnFontBlue)
    ON_UPDATE_COMMAND_UI(ID_FONT_BLUE, &Chw3_프로젝트 이름Doc::OnUpdateFontBlue)
    ON_UPDATE_COMMAND_UI(ID_PEN_BLUE, &Chw3_프로젝트 이름Doc::OnUpdatePenBlue)
    ON_COMMAND(ID_POS, &Chw3_프로젝트 이름Doc::OnPos)
    ON_UPDATE_COMMAND_UI(ID_POS, &Chw3_프로젝트 이름Doc::OnUpdatePos)
    ON_COMMAND(ID_SIZE, &Chw3_프로젝트 이름Doc::OnSize)
    ON_UPDATE_COMMAND_UI(ID_SIZE, &Chw3_프로젝트 이름Doc::OnUpdateSize)
    ON_COMMAND(ID_POLYGON, &Chw3_프로젝트 이름Doc::OnPolygon)
    ON_UPDATE_COMMAND_UI(ID_POLYGON, &Chw3_프로젝트 이름Doc::OnUpdatePolygon)
END_MESSAGE_MAP()
 
 
// Chw3_프로젝트 이름Doc 생성/소멸
 
Chw3_프로젝트 이름Doc::Chw3_프로젝트 이름Doc()
{
    // TODO: 여기에 일회성 생성 코드를 추가합니다.
    CList <CMyShape, CMyShape> m_list;
 
    m_type = 0//출력타입 처음0, 1:선 2:사각형 3:타원 4:텍스트 5:다각형
    m_Bcolor = RGB(000);
    m_Pcolor = RGB(000);
    m_Fcolor = RGB(000);
    m_bBrush = m_bPen = m_bFont = false;
    m_bSize = m_bPos = false;
    m_sidx = -1;
}
 
Chw3_프로젝트 이름Doc::~Chw3_프로젝트 이름Doc()
{
}
 
BOOL Chw3_프로젝트 이름Doc::OnNewDocument()
{
    if (!CDocument::OnNewDocument())
        return FALSE;
 
    // TODO: 여기에 재초기화 코드를 추가합니다.
    // SDI 문서는 이 문서를 다시 사용합니다.
 
    m_list.RemoveAll();
    m_bBrush = m_bPen = m_bFont = false;
    m_bSize = m_bPos = false;
 
    return TRUE;
}
 
 
// Chw3_프로젝트 이름Doc serialization
 
void Chw3_프로젝트 이름Doc::Serialize(CArchive& ar)
{
    if (ar.IsStoring())
    {
        ar << m_bBrush << m_bPen << m_bFont << m_Bcolor << m_Pcolor
            << m_Fcolor << m_bPos << m_bSize << m_type;
        m_list.Serialize(ar);
        // TODO: 여기에 저장 코드를 추가합니다.
    }
    else
    {
        ar >> m_bBrush >> m_bPen >> m_bFont >> m_Bcolor >> m_Pcolor 
            >> m_Fcolor >> m_bPos >> m_bSize >> m_type;
        m_list.Serialize(ar);
        // TODO: 여기에 로딩 코드를 추가합니다.
    }
}
 
#ifdef SHARED_HANDLERS
 
// 축소판 그림을 지원합니다.
void Chw3_프로젝트 이름Doc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds)
{
    // 문서의 데이터를 그리려면 이 코드를 수정하십시오.
    dc.FillSolidRect(lprcBounds, RGB(255255255));
 
    CString strText = _T("TODO: implement thumbnail drawing here");
    LOGFONT lf;
 
    CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
    pDefaultGUIFont->GetLogFont(&lf);
    lf.lfHeight = 36;
 
    CFont fontDraw;
    fontDraw.CreateFontIndirect(&lf);
 
    CFont* pOldFont = dc.SelectObject(&fontDraw);
    dc.DrawText(strText, lprcBounds, DT_CENTER | DT_WORDBREAK);
    dc.SelectObject(pOldFont);
}
 
// 검색 처리기를 지원합니다.
void Chw3_프로젝트 이름Doc::InitializeSearchContent()
{
    CString strSearchContent;
    // 문서의 데이터에서 검색 콘텐츠를 설정합니다.
    // 콘텐츠 부분은 ";"로 구분되어야 합니다.
 
    // 예: strSearchContent = _T("point;rectangle;circle;ole object;");
    SetSearchContent(strSearchContent);
}
 
void Chw3_프로젝트 이름Doc::SetSearchContent(const CString& value)
{
    if (value.IsEmpty())
    {
        RemoveChunk(PKEY_Search_Contents.fmtid, PKEY_Search_Contents.pid);
    }
    else
    {
        CMFCFilterChunkValueImpl *pChunk = NULL;
        ATLTRY(pChunk = new CMFCFilterChunkValueImpl);
        if (pChunk != NULL)
        {
            pChunk->SetTextValue(PKEY_Search_Contents, value, CHUNK_TEXT);
            SetChunkValue(pChunk);
        }
    }
}
 
#endif // SHARED_HANDLERS
 
// Chw3_프로젝트 이름Doc 진단
 
#ifdef _DEBUG
void Chw3_프로젝트 이름Doc::AssertValid() const
{
    CDocument::AssertValid();
}
 
void Chw3_프로젝트 이름Doc::Dump(CDumpContext& dc) const
{
    CDocument::Dump(dc);
}
#endif //_DEBUG
 
 
// Chw3_프로젝트 이름Doc 명령
 
 
void Chw3_프로젝트 이름Doc::OnLine()
{
    // TODO: 여기에 명령 처리기 코드를 추가합니다.
    m_type = 1;
    UpdateAllViews(NULL); //Invalidate와 같은 역할. 모든 뷰 업데이트
}
 
 
void Chw3_프로젝트 이름Doc::OnUpdateLine(CCmdUI *pCmdUI)
{
    // TODO: 여기에 명령 업데이트 UI 처리기 코드를 추가합니다.
    pCmdUI->SetCheck(m_type == 1);
}
 
 
void Chw3_프로젝트 이름Doc::OnRect()
{
    // TODO: 여기에 명령 처리기 코드를 추가합니다.
    m_type = 2;
    UpdateAllViews(NULL); //Invalidate와 같은 역할. 모든 뷰 업데이트
}
 
 
void Chw3_프로젝트 이름Doc::OnUpdateRect(CCmdUI *pCmdUI)
{
    // TODO: 여기에 명령 업데이트 UI 처리기 코드를 추가합니다.
    pCmdUI->SetCheck(m_type == 2);
}
 
 
void Chw3_프로젝트 이름Doc::OnEllipse()
{
    // TODO: 여기에 명령 처리기 코드를 추가합니다.
    m_type = 3;
    UpdateAllViews(NULL); //Invalidate와 같은 역할. 모든 뷰 업데이트
}
 
 
void Chw3_프로젝트 이름Doc::OnUpdateEllipse(CCmdUI *pCmdUI)
{
    // TODO: 여기에 명령 업데이트 UI 처리기 코드를 추가합니다.
    pCmdUI->SetCheck(m_type == 3);
}
 
 
void Chw3_프로젝트 이름Doc::OnText()
{
    // TODO: 여기에 명령 처리기 코드를 추가합니다.
    m_type = 4;
    UpdateAllViews(NULL); //Invalidate와 같은 역할. 모든 뷰 업데이트
}
 
 
void Chw3_프로젝트 이름Doc::OnUpdateText(CCmdUI *pCmdUI)
{
    // TODO: 여기에 명령 업데이트 UI 처리기 코드를 추가합니다.
    pCmdUI->SetCheck(m_type == 4);
}
 
 
void Chw3_프로젝트 이름Doc::OnPolygon()
{
    // TODO: 여기에 명령 처리기 코드를 추가합니다.
    m_type = 5;
    UpdateAllViews(NULL); //Invalidate와 같은 역할. 모든 뷰 업데이트
}
 
 
void Chw3_프로젝트 이름Doc::OnUpdatePolygon(CCmdUI *pCmdUI)
{
    // TODO: 여기에 명령 업데이트 UI 처리기 코드를 추가합니다.
    pCmdUI->SetCheck(m_type == 5);
}
 
 
void Chw3_프로젝트 이름Doc::OnBrushRed()
{
    // TODO: 여기에 명령 처리기 코드를 추가합니다.
    m_Bcolor = RGB(25500);
    m_bBrush = true;
    UpdateAllViews(NULL); //Invalidate와 같은 역할. 모든 뷰 업데이트
}
 
 
void Chw3_프로젝트 이름Doc::OnUpdateBrushRed(CCmdUI *pCmdUI)
{
    // TODO: 여기에 명령 업데이트 UI 처리기 코드를 추가합니다.
    pCmdUI->SetCheck(m_Bcolor == RGB(25500));
}
 
 
void Chw3_프로젝트 이름Doc::OnBrushGreen()
{
    // TODO: 여기에 명령 처리기 코드를 추가합니다.
    m_Bcolor = RGB(02550);
    m_bBrush = true;
    UpdateAllViews(NULL); //Invalidate와 같은 역할. 모든 뷰 업데이트
}
 
 
void Chw3_프로젝트 이름Doc::OnUpdateBrushGreen(CCmdUI *pCmdUI)
{
    // TODO: 여기에 명령 업데이트 UI 처리기 코드를 추가합니다.
    pCmdUI->SetCheck(m_Bcolor == RGB(02550));
}
 
 
void Chw3_프로젝트 이름Doc::OnBrushBlue()
{
    // TODO: 여기에 명령 처리기 코드를 추가합니다.
    m_Bcolor = RGB(00255);
    m_bBrush = true;
    UpdateAllViews(NULL); //Invalidate와 같은 역할. 모든 뷰 업데이트
}
 
 
void Chw3_프로젝트 이름Doc::OnUpdateBrushBlue(CCmdUI *pCmdUI)
{
    // TODO: 여기에 명령 업데이트 UI 처리기 코드를 추가합니다.
    pCmdUI->SetCheck(m_Bcolor == RGB(00255));
}
 
 
void Chw3_프로젝트 이름Doc::OnPenRed()
{
    // TODO: 여기에 명령 처리기 코드를 추가합니다.
    m_Pcolor = RGB(25500);
    m_bPen = true;
    UpdateAllViews(NULL); //Invalidate와 같은 역할. 모든 뷰 업데이트
}
 
 
void Chw3_프로젝트 이름Doc::OnUpdatePenRed(CCmdUI *pCmdUI)
{
    // TODO: 여기에 명령 업데이트 UI 처리기 코드를 추가합니다.
    pCmdUI->SetCheck(m_Pcolor == RGB(25500));
}
 
 
void Chw3_프로젝트 이름Doc::OnPenGreen()
{
    // TODO: 여기에 명령 처리기 코드를 추가합니다.
    m_Pcolor = RGB(02550);
    m_bPen = true;
    UpdateAllViews(NULL); //Invalidate와 같은 역할. 모든 뷰 업데이트
}
 
 
void Chw3_프로젝트 이름Doc::OnUpdatePenGreen(CCmdUI *pCmdUI)
{
    // TODO: 여기에 명령 업데이트 UI 처리기 코드를 추가합니다.
    pCmdUI->SetCheck(m_Pcolor == RGB(02550));
}
 
 
void Chw3_프로젝트 이름Doc::OnPenBlue()
{
    // TODO: 여기에 명령 처리기 코드를 추가합니다.
    m_Pcolor = RGB(00255);
    m_bPen = true;
    UpdateAllViews(NULL); //Invalidate와 같은 역할. 모든 뷰 업데이트
}
 
 
void Chw3_프로젝트 이름Doc::OnUpdatePenBlue(CCmdUI *pCmdUI)
{
    // TODO: 여기에 명령 업데이트 UI 처리기 코드를 추가합니다.
    pCmdUI->SetCheck(m_Pcolor == RGB(00255));
}
 
 
void Chw3_프로젝트 이름Doc::OnFontRed()
{
    // TODO: 여기에 명령 처리기 코드를 추가합니다.
    m_Fcolor = RGB(25500);
    m_bFont = true;
    UpdateAllViews(NULL); //Invalidate와 같은 역할. 모든 뷰 업데이트
}
 
 
void Chw3_프로젝트 이름Doc::OnUpdateFontRed(CCmdUI *pCmdUI)
{
    // TODO: 여기에 명령 업데이트 UI 처리기 코드를 추가합니다.
    pCmdUI->SetCheck(m_Fcolor == RGB(25500));
}
 
 
void Chw3_프로젝트 이름Doc::OnFontGreen()
{
    // TODO: 여기에 명령 처리기 코드를 추가합니다.
    m_Fcolor = RGB(02550);
    m_bFont = true;
    UpdateAllViews(NULL); //Invalidate와 같은 역할. 모든 뷰 업데이트
}
 
 
void Chw3_프로젝트 이름Doc::OnUpdateFontGreen(CCmdUI *pCmdUI)
{
    // TODO: 여기에 명령 업데이트 UI 처리기 코드를 추가합니다.
    pCmdUI->SetCheck(m_Fcolor == RGB(02550));
}
 
 
void Chw3_프로젝트 이름Doc::OnFontBlue()
{
    // TODO: 여기에 명령 처리기 코드를 추가합니다.
    m_Fcolor = RGB(00255);
    m_bFont = true;
    UpdateAllViews(NULL); //Invalidate와 같은 역할. 모든 뷰 업데이트
}
 
 
void Chw3_프로젝트 이름Doc::OnUpdateFontBlue(CCmdUI *pCmdUI)
{
    // TODO: 여기에 명령 업데이트 UI 처리기 코드를 추가합니다.
    pCmdUI->SetCheck(m_Fcolor == RGB(00255));
}
 
 
 
void Chw3_프로젝트 이름Doc::OnPos()
{
    // TODO: 여기에 명령 처리기 코드를 추가합니다.
    m_bPos = !m_bPos;
    m_bSize = false;
    m_type = 0;
    UpdateAllViews(NULL); //Invalidate와 같은 역할. 모든 뷰 업데이트
}
 
 
void Chw3_프로젝트 이름Doc::OnUpdatePos(CCmdUI *pCmdUI)
{
    // TODO: 여기에 명령 업데이트 UI 처리기 코드를 추가합니다.
    pCmdUI->SetCheck(m_bPos);
}
 
 
void Chw3_프로젝트 이름Doc::OnSize()
{
    // TODO: 여기에 명령 처리기 코드를 추가합니다.
    m_bSize = !m_bSize;
    m_bPos = false;
    m_type = 0;
    UpdateAllViews(NULL); //Invalidate와 같은 역할. 모든 뷰 업데이트
}
 
 
void Chw3_프로젝트 이름Doc::OnUpdateSize(CCmdUI *pCmdUI)
{
    // TODO: 여기에 명령 업데이트 UI 처리기 코드를 추가합니다.
    pCmdUI->SetCheck(m_bSize);
}
 
cs

 

- Doc.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
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
 
// hw3_프로젝트 이름Doc.h : Chw3_프로젝트 이름Doc 클래스의 인터페이스
//
 
 
#pragma once
 
#include "MyShape.h"
#include <afxtempl.h>
 
class Chw3_프로젝트 이름Doc : public CDocument
{
protected// serialization에서만 만들어집니다.
    Chw3_프로젝트 이름Doc();
    DECLARE_DYNCREATE(Chw3_프로젝트 이름Doc)
 
// 특성입니다.
public:
    CList <CMyShape, CMyShape> m_list;
    COLORREF m_Pcolor, m_Bcolor, m_Fcolor;
    TCHAR m_str[200]; int m_sidx;
    int m_type; //출력타입
    bool m_bBrush, m_bPen, m_bFont;
    bool m_bPos, m_bSize;
 
// 작업입니다.
public:
 
// 재정의입니다.
public:
    virtual BOOL OnNewDocument();
    virtual void Serialize(CArchive& ar);
#ifdef SHARED_HANDLERS
    virtual void InitializeSearchContent();
    virtual void OnDrawThumbnail(CDC& dc, LPRECT lprcBounds);
#endif // SHARED_HANDLERS
 
// 구현입니다.
public:
    virtual ~Chw3_프로젝트 이름Doc();
#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif
 
protected:
 
// 생성된 메시지 맵 함수
protected:
    DECLARE_MESSAGE_MAP()
 
#ifdef SHARED_HANDLERS
    // 검색 처리기에 대한 검색 콘텐츠를 설정하는 도우미 함수
    void SetSearchContent(const CString& value);
#endif // SHARED_HANDLERS
public:
    afx_msg void OnLine();
    afx_msg void OnUpdateLine(CCmdUI *pCmdUI);
    afx_msg void OnRect();
    afx_msg void OnUpdateRect(CCmdUI *pCmdUI);
    afx_msg void OnEllipse();
    afx_msg void OnUpdateEllipse(CCmdUI *pCmdUI);
    afx_msg void OnText();
    afx_msg void OnUpdateText(CCmdUI *pCmdUI);
    afx_msg void OnBrushRed();
    afx_msg void OnUpdateBrushRed(CCmdUI *pCmdUI);
    afx_msg void OnBrushGreen();
    afx_msg void OnBrushBlue();
    afx_msg void OnUpdateBrushGreen(CCmdUI *pCmdUI);
    afx_msg void OnUpdateBrushBlue(CCmdUI *pCmdUI);
    afx_msg void OnPenRed();
    afx_msg void OnUpdatePenRed(CCmdUI *pCmdUI);
    afx_msg void OnPenGreen();
    afx_msg void OnUpdatePenGreen(CCmdUI *pCmdUI);
    afx_msg void OnPenBlue();
    afx_msg void OnFontRed();
    afx_msg void OnUpdateFontRed(CCmdUI *pCmdUI);
    afx_msg void OnFontGreen();
    afx_msg void OnUpdateFontGreen(CCmdUI *pCmdUI);
    afx_msg void OnFontBlue();
    afx_msg void OnUpdateFontBlue(CCmdUI *pCmdUI);
    afx_msg void OnUpdatePenBlue(CCmdUI *pCmdUI);
    afx_msg void OnPos();
    afx_msg void OnUpdatePos(CCmdUI *pCmdUI);
    afx_msg void OnSize();
    afx_msg void OnUpdateSize(CCmdUI *pCmdUI);
    afx_msg void OnPolygon();
    afx_msg void OnUpdatePolygon(CCmdUI *pCmdUI);
};
 
cs
반응형

- View.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
// hw3_프로젝트 이름View.cpp : Chw3_프로젝트 이름View 클래스의 구현
//
 
#include "stdafx.h"
// SHARED_HANDLERS는 미리 보기, 축소판 그림 및 검색 필터 처리기를 구현하는 ATL 프로젝트에서 정의할 수 있으며
// 해당 프로젝트와 문서 코드를 공유하도록 해 줍니다.
#ifndef SHARED_HANDLERS
#include "hw3_프로젝트 이름.h"
#endif
 
#include "hw3_프로젝트 이름Doc.h"
#include "hw3_프로젝트 이름View.h"
 
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
 
 
// Chw3_프로젝트 이름View
 
IMPLEMENT_DYNCREATE(Chw3_프로젝트 이름View, CView)
 
BEGIN_MESSAGE_MAP(Chw3_프로젝트 이름View, CView)
    // 표준 인쇄 명령입니다.
    ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
    ON_WM_LBUTTONDOWN()
    ON_WM_LBUTTONUP()
//    ON_WM_MBUTTONDBLCLK()
    ON_WM_MOUSEMOVE()
    ON_WM_LBUTTONDBLCLK()
    ON_WM_CHAR()
    ON_WM_KEYDOWN()
END_MESSAGE_MAP()
 
// Chw3_프로젝트 이름View 생성/소멸
 
Chw3_프로젝트 이름View::Chw3_프로젝트 이름View()
{
    // TODO: 여기에 생성 코드를 추가합니다.
    CMyShape* m_Cmyshape;
}
 
Chw3_프로젝트 이름View::~Chw3_프로젝트 이름View()
{
}
 
BOOL Chw3_프로젝트 이름View::PreCreateWindow(CREATESTRUCT& cs)
{
    // TODO: CREATESTRUCT cs를 수정하여 여기에서
    //  Window 클래스 또는 스타일을 수정합니다.
 
    return CView::PreCreateWindow(cs);
}
 
// Chw3_프로젝트 이름View 그리기
 
void Chw3_프로젝트 이름View::OnDraw(CDC* pDC)
{
    Chw3_프로젝트 이름Doc* pDoc = GetDocument();
 
    ASSERT_VALID(pDoc);
    if (!pDoc)
        return;
 
    if (pDoc->m_type == 4&&!(pDoc->m_list.IsEmpty()))
    {
        CRect rc(m_start.x - 10, m_start.y - 10, m_start.x + 400, m_start.y + 200);
        CPen pen(PS_DOT, 1, RGB(000));
        pDC->SelectObject(&pen);
        pDC->Rectangle(rc);
 
        POSITION pos = pDoc->m_list.GetTailPosition();
        CMyShape& temp = pDoc->m_list.GetPrev(pos);
 
        // 화면 출력용 폰트를 선택한다.
        CFont font; 
        font.CreatePointFont(temp.m_fsize, _T("Arial"));
        pDC->SelectObject(&font);
        pDC->SetTextColor(pDoc->m_Fcolor);
 
        // 현재까지 입력된 글자를 화면에 출력한다.
        CRect rect(m_start.x, m_start.y, m_start.x + 400, m_start.y + 200);
        pDC->DrawTextW(pDoc->m_str, -1&rect, DT_WORDBREAK);
    }
    //폴리라인 그리기
    if (!tmp.m_bPolygon && pDoc->m_type == 5)
    {
        //리스트에 들어있는 CPoint들을 폴리라인
        CPen pen(PS_SOLID, 1, pDoc->m_Pcolor);
        pDC->SelectObject(&pen);
        pDC->Polyline(tmp.m_polygon, tmp.m_idx + 1);
    }
    else
    {
        tmp.m_idx = -1;
        tmp.m_bPolygon = false;
    }
 
    // TODO: 여기에 원시 데이터에 대한 그리기 코드를 추가합니다.
    
    //도형 그리기
    POSITION pos = pDoc->m_list.GetHeadPosition();
 
    while (pos != NULL)
    {
        CMyShape& temp = pDoc->m_list.GetNext(pos);
        CBrush brush(temp.m_Bcolor);
        CPen pen(PS_SOLID, 1, temp.m_Pcolor);
        pDC->SelectObject(&pen);
        pDC->SelectObject(&brush);
 
        if (temp.GetType() == 1)// 선
        {
            pDC->MoveTo(temp.GetStartPoint()->x, temp.GetStartPoint()->y);
            pDC->LineTo(temp.GetEndPoint()->x, temp.GetEndPoint()->y);
        }
        if (temp.GetType() == 2)// 사각형
        {
            pDC->Rectangle(temp.GetStartPoint()->x, temp.GetStartPoint()->y, temp.GetEndPoint()->x, temp.GetEndPoint()->y);
        }
        if (temp.GetType() == 3)// 타원
        {
            pDC->Ellipse(temp.GetStartPoint()->x, temp.GetStartPoint()->y, temp.GetEndPoint()->x, temp.GetEndPoint()->y);
        }
        if (temp.GetType() == 4)// 텍스트
        {
            // 화면 출력용 폰트를 선택한다.
            CFont font;
            font.CreatePointFont(temp.m_fsize, _T("Arial"));
            pDC->SelectObject(&font);
            pDC->SetTextColor(temp.m_Fcolor);
 
            // 현재까지 입력된 글자를 화면에 출력한다.
            CRect rect(temp.GetStartPoint()->x, temp.GetStartPoint()->y, temp.GetStartPoint()->+ 400, temp.GetStartPoint()->+ 200);
            pDC->DrawTextW(temp.m_str, -1&rect, DT_WORDBREAK);
        }
        if (temp.GetType() == 5)// 다각형
        {
            if (temp.m_bPolygon)// 다각형 완성
            {
                //리스트에 들어있는 CPoint들을 폴리곤
                pDC->Polygon(temp.m_polygon, temp.m_idx + 1);
            }
        }
    }
 
}
 
 
// Chw3_프로젝트 이름View 인쇄
 
BOOL Chw3_프로젝트 이름View::OnPreparePrinting(CPrintInfo* pInfo)
{
    // 기본적인 준비
    return DoPreparePrinting(pInfo);
}
 
void Chw3_프로젝트 이름View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
    // TODO: 인쇄하기 전에 추가 초기화 작업을 추가합니다.
}
 
void Chw3_프로젝트 이름View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
    // TODO: 인쇄 후 정리 작업을 추가합니다.
}
 
 
// Chw3_프로젝트 이름View 진단
 
#ifdef _DEBUG
void Chw3_프로젝트 이름View::AssertValid() const
{
    CView::AssertValid();
}
 
void Chw3_프로젝트 이름View::Dump(CDumpContext& dc) const
{
    CView::Dump(dc);
}
 
Chw3_프로젝트 이름Doc* Chw3_프로젝트 이름View::GetDocument() const // 디버그되지 않은 버전은 인라인으로 지정됩니다.
{
    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(Chw3_프로젝트 이름Doc)));
    return (Chw3_프로젝트 이름Doc*)m_pDocument;
}
#endif //_DEBUG
 
 
// Chw3_프로젝트 이름View 메시지 처리기
 
 
void Chw3_프로젝트 이름View::OnLButtonDown(UINT nFlags, CPoint point)
{
    // TODO: 여기에 메시지 처리기 코드를 추가 및/또는 기본값을 호출합니다.
    Chw3_프로젝트 이름Doc* pDoc = GetDocument();
    m_start = point;
    m_end = point;
    m_bDraw = true;
    memset(pDoc->m_str, 0sizeof(pDoc->m_str)); //텍스트 초기화
    pDoc->m_sidx = -1;
 
    SetCapture();
    SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW)); // 윈도우 어플리케이션의 포인터로부터 LoadStandardCursor가져다 씀
 
    //다각형 모드
    if (pDoc->m_type == 5)
    {
        tmp.m_polygon[++tmp.m_idx] = point;
    }
 
    CView::OnLButtonDown(nFlags, point);
}
 
 
void Chw3_프로젝트 이름View::OnLButtonUp(UINT nFlags, CPoint point)
{
    // TODO: 여기에 메시지 처리기 코드를 추가 및/또는 기본값을 호출합니다.
    m_end = point;
    m_bDraw = false;
    CMyShape temp;
    Chw3_프로젝트 이름Doc* pDoc = GetDocument();
 
    //텍스트 경우, 캐럿 생성 및 표시
    if (pDoc->m_type == 4)
    {
        CreateSolidCaret(2020); 
        SetCaretPos(CPoint(m_start.x,m_start.y));
        ShowCaret();
    }
 
    ReleaseCapture();
 
    //위치조정or크기조정
    if (pDoc->m_bPos || pDoc->m_bSize)
    {
        POSITION pos = pDoc->m_list.GetHeadPosition();
 
        while (pos != NULL)
        {
            m_Cmyshape = &pDoc->m_list.GetNext(pos);
 
            // 사각형 정규화->높이와 너비 양수화
            m_Cmyshape->GetRect().NormalizeRect();
 
            // 사각형 rtmp 영역 안에 좌클릭한 point가 들어있을 경우
            if (m_Cmyshape->GetRect().PtInRect(point))
            {
                break;
            }
        }
    }
 
    if (pDoc->m_type != 5)
    {
        temp.SetStartPoint(m_start);
        temp.SetEndPoint(m_end);
        temp.SetType(pDoc->m_type);
        temp.m_Bcolor = pDoc->m_Bcolor;
        temp.m_Pcolor = pDoc->m_Pcolor;
        temp.m_Fcolor = pDoc->m_Fcolor;
 
        pDoc->m_list.AddTail(temp);
    }
 
    Invalidate();
    CView::OnLButtonUp(nFlags, point);
}
 
 
void Chw3_프로젝트 이름View::OnMouseMove(UINT nFlags, CPoint point)
{
    // TODO: 여기에 메시지 처리기 코드를 추가 및/또는 기본값을 호출합니다.
    Chw3_프로젝트 이름Doc* pDoc = GetDocument();
 
    if (m_bDraw)
    {
        HideCaret(); //캐럿 숨김
        ::DestroyCaret(); //파괴
 
        CClientDC dc(this);
        CBrush brush(pDoc->m_Bcolor); 
        CPen pen(PS_SOLID, 1, pDoc->m_Pcolor);
        dc.SelectObject(&pen);
        dc.SelectObject(&brush);
 
        if (pDoc->m_type == 1//선
        {
            //이전에 그린 도형을 지운다
            dc.SetROP2(R2_NOTXORPEN); //같으면 지워지고 다르면 안지워짐
            dc.MoveTo(m_start.x, m_start.y);
            dc.LineTo(m_end.x, m_end.y);
 
            // 새로운 도형을 그린다.
            dc.SetROP2(R2_NOTXORPEN);
            m_end = point;
            dc.MoveTo(m_start.x, m_start.y);
            dc.LineTo(m_end.x, m_end.y);
        }
        if (pDoc->m_type == 2//사각형
        {
            //이전에 그린 도형을 지운다
            dc.SetROP2(R2_COPYPEN); //같으면 지워지고 다르면 안지워짐
            dc.Rectangle(m_start.x, m_start.y, m_end.x, m_end.y);
            // 새로운 도형을 그린다.
            dc.SetROP2(R2_COPYPEN);
            m_end = point;
            dc.Rectangle(m_start.x, m_start.y, m_end.x, m_end.y);
        }
        if (pDoc->m_type == 3//타원
        {
            //이전에 그린 도형을 지운다
            dc.SetROP2(R2_COPYPEN); //같으면 지워지고 다르면 안지워짐
            dc.Ellipse(m_start.x, m_start.y, m_end.x, m_end.y);
            // 새로운 도형을 그린다.
            dc.SetROP2(R2_COPYPEN);
            m_end = point;
            dc.Ellipse(m_start.x, m_start.y, m_end.x, m_end.y);
        }
    }
 
 
    CView::OnMouseMove(nFlags, point);
}
 
 
void Chw3_프로젝트 이름View::OnLButtonDblClk(UINT nFlags, CPoint point)
{
    // TODO: 여기에 메시지 처리기 코드를 추가 및/또는 기본값을 호출합니다.
    Chw3_프로젝트 이름Doc* pDoc = GetDocument();
 
    if (pDoc->m_type == 5)
    {
        tmp.m_bPolygon = true;
        tmp.SetType(pDoc->m_type);
        tmp.m_Bcolor = pDoc->m_Bcolor;
        tmp.m_Pcolor = pDoc->m_Pcolor;
        
        pDoc->m_list.AddTail(tmp);
 
        tmp.m_idx = -1;
        tmp.m_bPolygon = false;
 
        Invalidate();
    }
 
    CView::OnLButtonDblClk(nFlags, point);
}
 
 
void Chw3_프로젝트 이름View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
    // TODO: 여기에 메시지 처리기 코드를 추가 및/또는 기본값을 호출합니다.
    Chw3_프로젝트 이름Doc* pDoc = GetDocument(); //데이터가 pDoc(다큐먼트)에 존재. 다큐먼트 포인터를 생성해서 다큐먼트 내용을 가져와야함.
 
    HideCaret(); //키 입력이 들어오면 캐럿 숨기고
    ::DestroyCaret(); //파괴
 
    // Backspace 입력 시 맨 마지막 글자를 삭제한다.
    if (nChar == _T('\b'))
    {
        if (pDoc->m_sidx + 1 > 0)
        {
            pDoc->m_str[pDoc->m_sidx--= 0;
        }
    }
    // 그 밖의 경우에는 동적 배열에 글자를 추가한다.
    else
    {
        pDoc->m_str[++pDoc->m_sidx] = nChar;
        pDoc->m_list.GetTail().m_str[pDoc->m_sidx] = nChar; pDoc->m_list.GetTail().m_sidx = pDoc->m_sidx;
    }
 
    // 데이터가 수정되었음을 도큐먼트 객체에 알린다.
    pDoc->SetModifiedFlag();
    // 뷰의 화면을 갱신한다.
    Invalidate();
 
    CView::OnChar(nChar, nRepCnt, nFlags);
}
 
 
 
void Chw3_프로젝트 이름View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
    // TODO: 여기에 메시지 처리기 코드를 추가 및/또는 기본값을 호출합니다.
    
    //편집 모드
    Chw3_프로젝트 이름Doc* pDoc = GetDocument();
 
    //위치조정
    if (pDoc->m_bPos)
    {
        CPoint* st = m_Cmyshape->GetStartPoint();
        CPoint* ed = m_Cmyshape->GetEndPoint();
 
        if (nChar == VK_UP)
        {
            st->-= 5;
            ed->-= 5;
        }
        if (nChar == VK_DOWN)
        {
            st->+= 5;
            ed->+= 5;
        }
        if (nChar == VK_LEFT)
        {
            st->-= 5;
            ed->-= 5;
        }
        if (nChar == VK_RIGHT)
        {
            st->+= 5;
            ed->+= 5;
        }
    }
    //크기조정
    if (pDoc->m_bSize)
    {
        CPoint* st = m_Cmyshape->GetStartPoint();
        CPoint* ed = m_Cmyshape->GetEndPoint();
        if (nChar == VK_UP)
        {
            st->-= 3;
            st->-= 3;
            ed->+= 3;
            ed->+= 3;
        }
        if (nChar == VK_DOWN)
        {
            st->+= 3;
            st->+= 3;
            ed->-= 3;
            ed->-= 3;
        }
    }
 
    Invalidate();
    CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
 
cs

 

- View.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
 
// hw3_프로젝트 이름View.h : Chw3_프로젝트 이름View 클래스의 인터페이스
//
 
#pragma once
 
#include "MyShape.h"
#include "hw3_프로젝트 이름Doc.h"
 
class Chw3_프로젝트 이름View : public CView
{
protected// serialization에서만 만들어집니다.
    Chw3_프로젝트 이름View();
    DECLARE_DYNCREATE(Chw3_프로젝트 이름View)
 
// 특성입니다.
public:
    Chw3_프로젝트 이름Doc* GetDocument() const;
    CMyShape* m_Cmyshape;
    CMyShape tmp;
    CPoint m_start, m_end; //출력위치
    bool m_bDraw = false;
 
// 작업입니다.
public:
 
// 재정의입니다.
public:
    virtual void OnDraw(CDC* pDC);  // 이 뷰를 그리기 위해 재정의되었습니다.
    virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
    virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
    virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
    virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
 
// 구현입니다.
public:
    virtual ~Chw3_프로젝트 이름View();
#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif
 
protected:
 
// 생성된 메시지 맵 함수
protected:
    DECLARE_MESSAGE_MAP()
public:
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
//    afx_msg void OnMButtonDblClk(UINT nFlags, CPoint point);
    afx_msg void OnMouseMove(UINT nFlags, CPoint point);
    afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
    afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
    afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
};
 
#ifndef _DEBUG  // hw3_프로젝트 이름View.cpp의 디버그 버전
inline Chw3_프로젝트 이름Doc* Chw3_프로젝트 이름View::GetDocument() const
   { return reinterpret_cast<Chw3_프로젝트 이름Doc*>(m_pDocument); }
#endif
 
 
cs

 

- MyShape.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// MyShape.cpp : 구현 파일입니다.
//
 
#include "stdafx.h"
#include "hw3_프로젝트 이름.h"
#include "MyShape.h"
 
 
// CMyShape
CMyShape::CMyShape()
{
    m_type = 0// 1:선 2:사각형 3:타원 4:텍스트 5:다각형
    m_start = m_end = CPoint(00);
    m_rect.TopLeft() = m_start;
    m_rect.BottomRight() = m_end;
    m_idx = -1, m_fsize = 150;
    m_bPolygon = false;
 
    memset(m_str, 0sizeof(m_str)); //텍스트 초기화
    m_sidx = -1;
}
 
CMyShape::CMyShape(const CMyShape& t)
{
    //t내용을 *this에
    m_start = t.m_start;
    m_end = t.m_end;
    m_type = t.m_type;
 
    m_sidx = t.m_sidx;
    for (int i = 0; i <= t.m_sidx; i++)
    {
        m_str[i] = t.m_str[i];
    }
    
    m_Bcolor = t.m_Bcolor;
    m_Fcolor = t.m_Fcolor;
    m_Pcolor = t.m_Pcolor;
    m_rect = t.m_rect;
    m_bPolygon = t.m_bPolygon;
    m_fsize = t.m_fsize;
 
    m_idx = t.m_idx;
    for (int i = 0; i <= t.m_idx; i++)
    {
        m_polygon[i] = t.m_polygon[i];
    }
}
 
CMyShape::~CMyShape()
{
}
 
 
// CMyShape 멤버 함수
 
IMPLEMENT_SERIAL(CMyShape, CObject, 1)
 
void CMyShape::Serialize(CArchive& ar)
{
    CObject::Serialize(ar);
 
    if (ar.IsStoring())//저장
    {
        ar << m_idx << m_sidx << m_fsize << m_rect << m_start 
            << m_end << m_type << m_Pcolor << m_Bcolor << m_Fcolor << m_type 
            << m_bPolygon << m_polygon[m_idx] << m_str[m_sidx];
 
    }
    else//열기
    {
        ar >> m_idx >> m_sidx >> m_fsize >> m_rect >> m_start
            >> m_end >> m_type >> m_Pcolor >> m_Bcolor >> m_Fcolor >> m_type
            >> m_bPolygon >> m_polygon[m_idx] >> m_str[m_sidx];
    }
}
 
CMyShape& CMyShape::operator=(const CMyShape& t)
{
    //t내용을 *this에 넣고 *this를 반환
 
    m_start = t.m_start;
    m_end = t.m_end;
    m_type = t.m_type;
 
    m_sidx = t.m_sidx;
    for (int i = 0; i <= m_sidx; i++)
    {
        m_str[i] = t.m_str[i];
    }
 
    m_Bcolor = t.m_Bcolor;
    m_Fcolor = t.m_Fcolor;
    m_Pcolor = t.m_Pcolor;
    m_rect = t.m_rect;
    m_bPolygon = t.m_bPolygon;
    m_fsize = t.m_fsize;
 
    m_idx = t.m_idx;
    for (int i = 0; i <= t.m_idx; i++)
    {
        m_polygon[i] = t.m_polygon[i];
    }
 
    return *this;
}
 
void CMyShape::SetStartPoint(CPoint st)
{
    m_start = st;
    m_rect.TopLeft() = st;
}
 
CPoint* CMyShape::GetStartPoint()
{
    return &m_start;
}
 
void CMyShape::SetEndPoint(CPoint ed)
{
    m_end = ed;
    m_rect.BottomRight() = ed;
}
 
CPoint* CMyShape::GetEndPoint()
{
    return &m_end;
}
 
void CMyShape::SetType(int tp)
{
    m_type = tp;
}
 
int CMyShape::GetType()
{
    return m_type;
}
 
CRect& CMyShape::GetRect()
{
    return m_rect;
}
 
void CMyShape::SetRect(CRect rect)
{
    m_rect = rect;
    m_start = m_rect.TopLeft();
    m_end = m_rect.BottomRight();
}
cs

 

- MyShape.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
#pragma once
 
// CMyShape 명령 대상입니다.
 
class CMyShape : public CObject
{
    DECLARE_SERIAL(CMyShape)
 
public:
    TCHAR m_str[200]; int m_sidx; //텍스트 관련
 
    COLORREF m_Pcolor, m_Bcolor, m_Fcolor;
    CPoint m_polygon[200];
    int m_idx, m_fsize;
    bool m_bPolygon;
 
public:
    CMyShape();
    CMyShape(const CMyShape& t);
    CMyShape& operator=(const CMyShape& t);
    virtual ~CMyShape();
 
    void SetStartPoint(CPoint st);
    void SetEndPoint(CPoint ed);
    CPoint *GetStartPoint();
    CPoint * GetEndPoint();
    void SetType(int tp);
    int GetType();
    CRect& GetRect();
    void CMyShape::SetRect(CRect rect);
 
    void Serialize(CArchive& ar);
 
private:
    CPoint m_start, m_end; //출력위치
    CRect m_rect; 
    int m_type; //출력타입
};
 
 
 
cs

 

 

 

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

https://inf.run/3XmSH

 

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

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

www.inflearn.com

 

반응형