mfc_Data_Manage - 8BitsCoding/RobotMentor GitHub Wiki


  • ์ฝ”๋“œ์˜ ์ค‘๊ฐ„ ์‚ฝ์ž…/์‚ญ์ œ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ : CPtrArray
  • ์ฝ”๋“œ์˜ ์ค‘๊ฐ„ ์‚ฝ์ž…/์‚ญ์ œ๊ฐ€ ๋งŽ์€ ๊ฒฝ์šฐ : CPtrList
// Dlg.h
//CPtrArray m_pos_list;
CPtrList m_pos_list;

์ขŒํด๋ฆญ ์‹œ ๋„ค๋ชจ ์ถ”๊ฐ€

void CMFCApplication3Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
	POINT * p = new POINT;
	p->x = point.x;
	p->y = point.y;

	// CPtrList ๋ฐฉ์‹
	m_pos_list.AddTail(p);

	// CPtrArray ๋ฐฉ์‹
	// m_pos_list.Add(p);

	CClientDC dc(this);
	dc.Rectangle(point.x - 10, point.y - 10, point.x + 10, point.y + 10);

	CDialogEx::OnLButtonDown(nFlags, point);
}

์šฐ ํด๋ฆญ ์‹œ ๋„ค๋ชจ ์ œ๊ฑฐ

void CMFCApplication3Dlg::OnRButtonDown(UINT nFlags, CPoint point)
{
	/* // CPtrArray ๋ฐฉ์‹
	POINT* p;
	int count = m_pos_list.GetCount();
	CRect r;

	for (int i = 0; i < count; i++) {
		p = (POINT*)m_pos_list.GetAt(i);
		if (p != NULL) {
			r.SetRect(p->x - 10, p->y - 10, p->x + 10, p->y + 10);
			if (r.PtInRect(point)) {
				// ๋‚ด๋ถ€์— ์žˆ์Œ
				delete p;
				m_pos_list.SetAt(i, NULL);
				// delete๋ฅผ ํ•ด๋„ ๋’ค์— ์ฃผ์†Œ๊ฐ€ ์•ž์œผ๋กœ ๋‹น๊ฒจ์ง€์ง€ ์•Š๊ธฐ์— NULL์„ ๋„ฃ์–ด์ค˜์•ผํ•จ!
				Invalidate();
				break;
			}
		}
	}
	*/

	// CPtrList ๋ฐฉ์‹
	POINT * p;
	POSITION pos = m_pos_list.GetHeadPosition(), check_pos;
	CRect r;
	while (pos != NULL) {
		check_pos = pos;
		p = (POINT*)m_pos_list.GetNext(pos);
		if (p != NULL) {
			r.SetRect(p->x - 10, p->y - 10, p->x + 10, p->y + 10);
			if (r.PtInRect(point)) {
				delete p;
				m_pos_list.RemoveAt(check_pos);
				Invalidate();
				break;
			}
		}
	}

	CDialogEx::OnRButtonDown(nFlags, point);
}
void CMFCApplication3Dlg::OnPaint()
{
	CPaintDC dc(this); // ๊ทธ๋ฆฌ๊ธฐ๋ฅผ ์œ„ํ•œ ๋””๋ฐ”์ด์Šค ์ปจํ…์ŠคํŠธ์ž…๋‹ˆ๋‹ค.

	if (IsIconic())
	{
        // ...
	}
	else
	{
		/* // CPtrArray ๋ฐฉ์‹
		POINT * p;
		int count = m_pos_list.GetCount();

		for (int i = 0; i < count; i++) {
			p = (POINT*)m_pos_list.GetAt(i);
			if (p != NULL) {
				dc.Rectangle(p->x - 10, p->y - 10, p->x + 10, p->y + 10);
			}
		}
		*/

		// CPtrList  ๋ฐฉ์‹
		POINT * p;
		POSITION pos = m_pos_list.GetHeadPosition();
		while (pos != NULL) {
			p = (POINT*)m_pos_list.GetNext(pos);
			dc.Rectangle(p->x - 10, p->y - 10, p->x + 10, p->y + 10);
		}
		// CDialogEx::OnPaint();
	}
}
void CMFCApplication3Dlg::OnDestroy()
{
	CDialogEx::OnDestroy();

	/*  // CPtrArray ๋ฐฉ์‹
	POINT * p;
	int count = m_pos_list.GetCount();
	for (int i = 0; i < count; i++) {
		p = (POINT*)m_pos_list.GetAt(i);
		if(p!=NULL) delete p;
	}
	*/

	// CPtrList ๋ฐฉ์‹
	POINT * p;
	POSITION pos = m_pos_list.GetHeadPosition();
	while (pos != NULL) {
		p = (POINT*)m_pos_list.GetNext(pos);
		delete p;
	}
}