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;
}
}