mfc_five - 8BitsCoding/RobotMentor GitHub Wiki
์ค๋ชฉ ํ๋ก๊ทธ๋จ ๋ง๋ค๊ธฐ(๊ทธ๋ฆผ๋ง)
// Dlg.h
#define X_COUNT 19
#define Y_COUNT 19
#define G_CX 30 // GRID X
#define G_CX_H G_CX/2 // GRID X/2
// ...
CPen m_grid_pen;
char m_step = 0; // 0 - ํ / 1 - ๋ฐฑ
char m_dol[Y_COUNT][X_COUNT]; // 0 - ๋ ์์ / 1 - ํ / 2 - ๋ฐฑ
CMFCApplication1Dlg::CMFCApplication1Dlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_MFCAPPLICATION1_DIALOG, pParent),
m_grid_pen(PS_SOLID, 1, RGB(144, 90, 40))
{
// ...
void CMFCApplication1Dlg::OnPaint()
{
CPaintDC dc(this); // ๊ทธ๋ฆฌ๊ธฐ๋ฅผ ์ํ ๋๋ฐ์ด์ค ์ปจํ
์คํธ์
๋๋ค.
if (IsIconic())
{
// ...
}
else
{
CBrush * p_old_brush = dc.GetCurrentBrush();
CPen * p_old_pen = dc.SelectObject(&m_grid_pen);
for (int i = 0; i < X_COUNT; i++) {
// ์์ง์
dc.MoveTo(G_CX_H + i * G_CX, G_CX_H);
dc.LineTo(G_CX_H + i * G_CX, G_CX_H + (X_COUNT-1) * G_CX);
// ์ํ์
dc.MoveTo(G_CX_H, G_CX_H + i * G_CX);
dc.LineTo(G_CX_H + (Y_COUNT-1) * G_CX, G_CX_H + i * G_CX);
}
for (int y = 0; y < Y_COUNT; y++) {
for (int x = 0; x < X_COUNT; x++) {
if (m_dol[y][x] != 0) {
if (m_dol[y][x] == 1) dc.SelectStockObject(BLACK_BRUSH);
else dc.SelectStockObject(WHITE_BRUSH);
dc.Ellipse(x * G_CX, y * G_CX, x * G_CX + G_CX, y * G_CX + G_CX);
}
}
}
dc.SelectObject(p_old_brush);
dc.SelectObject(p_old_pen);
// CDialogEx::OnPaint();
}
}
void CMFCApplication1Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
int x = point.x / G_CX;
int y = point.y / G_CX;
if (x < X_COUNT && y < Y_COUNT && m_dol[y][x] == 0) {
m_dol[y][x] = m_step + 1;
CClientDC dc(this);
CGdiObject * p_old_brush;
CPen * p_old_pen = dc.SelectObject(&m_grid_pen);
if (m_step == 0) p_old_brush = dc.SelectStockObject(BLACK_BRUSH);
else p_old_brush = dc.SelectStockObject(WHITE_BRUSH);
dc.Ellipse(x * G_CX, y * G_CX, x * G_CX + G_CX, y * G_CX + G_CX);
dc.SelectObject(p_old_brush);
dc.SelectObject(p_old_pen);
m_step = !m_step;
}
CDialogEx::OnLButtonDown(nFlags, point);
}