mfc_poly_3 - 8BitsCoding/RobotMentor GitHub Wiki


์˜ค๋ชฉํŒ ๋งŒ๋“ค๊ธฐ

// Dlg.h
CBrush m_select_brush, m_unselect_brush;
CPen m_select_pen, m_unselect_pen;
int m_index = -1;			// 0 ~ 17
//int m_index_x = -1;		// 0 ~ 5
//int m_index_y = -1;		// 0 ~ 2
void CMFCApplication1Dlg::OnPaint()
{
	CPaintDC dc(this); // ๊ทธ๋ฆฌ๊ธฐ๋ฅผ ์œ„ํ•œ ๋””๋ฐ”์ด์Šค ์ปจํ…์ŠคํŠธ์ž…๋‹ˆ๋‹ค.

	if (IsIconic())
	{
        // ...
	}
	else
	{
		CBrush * p_old_brush = dc.SelectObject(&m_unselect_brush);
		CPen * p_old_pen = dc.SelectObject(&m_unselect_pen);

		int x, y;

		for (y = 0; y < 3; y++) {
			for (x = 0; x < 6; x++) {
				dc.Rectangle(50 + x * 100, 50 + y* 100, 151 + x * 100, 151 + y*100);
			}
		}

		if (m_index != -1) {
			x = m_index % 7;
			y = m_index / 7;

			dc.SelectObject(&m_select_brush);
			dc.SelectObject(&m_select_pen);

			dc.Ellipse(x * 100, y * 100, 101 + x * 100, 101 + y * 100);
		}
		
		dc.SelectObject(p_old_brush);
		dc.SelectObject(p_old_pen);

		// CDialogEx::OnPaint();
	}
}
void CMFCApplication1Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
	//if (point.y < 100) {
		/*
		m_index_x = -1;

		for (int i = 0; i < 6; i++) {
			if (point.x < 100 + i * 100) {
				m_index_x = i;
				break;
			}
		}
		*/

		/*
		// ์ฝ”๋“œ๋ฅผ ๊ฐ„๋‹จํžˆ
		m_index_x = point.x / 100;
		m_index_y = point.y / 100;
		if (m_index_x >= 6 || m_index_y >= 3) m_index_x = -1;
		*/
		
	point.x = point.x / 100;		// 0 ~ 5
	point.y = point.y / 100;		// 0 ~ 2

	if (point.x >= 7 || point.y >= 4) m_index = -1;
	m_index = point.y * 7 + point.x;

	Invalidate(TRUE);
	//}

	CDialogEx::OnLButtonDown(nFlags, point);
}