mfc_poly_2 - 8BitsCoding/RobotMentor GitHub Wiki
λ€μ°¨μ λ°°μ΄μ λ€λͺ¨ μ€ νλλ₯Ό μ ννλ©΄ μμ λ³κ²½
// Dlg.h
public:
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(x * 100, y* 100, 101 + x * 100, 101 + y*100);
}
}
if (m_index != -1) {
x = m_index % 6;
y = m_index / 6;
dc.SelectObject(&m_select_brush);
dc.SelectObject(&m_select_pen);
dc.Rectangle(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 >= 6 || point.y >= 3) m_index = -1;
m_index = point.y * 6 + point.x;
Invalidate(TRUE);
//}
CDialogEx::OnLButtonDown(nFlags, point);
}