βInvalidate() -> View
μ΄ ν¨μλ CWndμμ νμλ ν¨μλ‘μ¨ View(CWndμμ νμλ ν΄λμ€μμ) ν΄λμ€ μμμ μ€νμ΄ κ°λ₯νλ€.
Viewν΄λμ€ μμμλ OnDraw() ν¨μλ WM_PAINT λ©μΈμ§μ μν΄ νΈμΆλλλ‘ λ§λ€μ΄μ Έ μλ€. μ΄λ¬ν λ©μΈμ§λ₯Ό μ¬μ©μκ° μνλ μμ μ μμλ‘ νΈμΆν μ μκ² ν΄μ£Όλ λ°©λ²μ€ νλκ° Invalidate() ν¨μλΌκ³ ν μ μκ² λ€.
μ΄ ν¨μλ νΈμΆν ν΄λΌμ΄μΈνΈ μλμ°μ νλ©΄μ 무ν¨νμν¨λ€. νλ©΄μ΄ λ¬΄ν¨νλλ©΄ μμ€ν
μ WM_PAINT λ©μΈμ§λ₯Ό λ°μμν¨λ€. μ¦ μνλ μλμ°μ νλ©΄μ κ°μ λ‘ κ°±μ ν λ μ¬μ©νλ€.
βUpdateAllViews() -> Docu
κ·Έλ λ€λ©΄ View ν΄λμ€κ° μλ Document ν΄λμ€μμλ Invalidate() ν¨μλ₯Ό μ΄λ»κ² μ€νμν¬μ μμκΉ?
CWndν΄λμ€μμ νμλκ²μ΄ μλ Document ν΄λμ€λ Invalidate()λ₯Ό μ¬μ©ν μλ μλ€.
νμ§λ§ Invalidate() ν¨μμ λ§μ°¬κ°μ§λ‘ ν΄λΌμ΄μΈνΈμ μμμ 무ν¨ν μν€λ UpdateAllViews() ν¨μλ₯Ό μ¬μ©ν μ μλ€.
β RAW νμΌ μ½κΈ°
MDI λͺ¨λ
λΉμ£ΌμΌ μ€νμΌ λ° μ : Windows μν/κΈ°λ³Έ
λ¬Έμν
νλ¦Ώ μμ± : νμΌνμ₯λͺ
: RAW
μμ±λ ν΄λμ€ : κΈ°λ³Έν΄λμ€ -> CScrollView
Docu μ μΈ
public:
unsigned char m_InImg[256][256];
unsigned char m_OutImg[256][256];
μ΄κΈ°ν
m_InImg[256][256] = NULL
m_OutImg[256][256] = NULL
Draw()μμ
for (int i = 0; i < 256; i++)
{
for (int j = 0; j < 256; j++)
{
unsigned char InVal = pDoc->m_InImg[i][j];
unsigned char OutVal = pDoc->m_OutImg[i][j];
pDC->SetPixel(j, i, RGB(InVal, InVal, InVal));
pDC->SetPixel(j+300, i, RGB(OutVal, OutVal, OutVal));
}
}
β νμΌ μμ
λ©λ΄μ Reverse νλ λ§λ€κ³
μμ±μ
ID : IDW_REVERSE_IMG
Caption : μμκ³μ°(Doc)
Prompt : μ΄λ―Έμ§μ μμκ°μ κ³μ°
μμ λ Docμμ IDW_REVERSE_IMGλ₯Ό μΆκ°
void CWinTestDoc::OnIdwReverseImg()
{
// TODO: μ¬κΈ°μλͺ
λ Ήμ²λ¦¬κΈ°μ½λλ₯ΌμΆκ°ν©λλ€.
AfxMessageBox(_T("μμκ³μ°")); //λ©λ΄μ ν¨μ μ°κ²° νμΈ
}
void CWinTestDoc::OnIdwReverseImg()
{
// TODO: μ¬κΈ°μλͺ
λ Ήμ²λ¦¬κΈ°μ½λλ₯ΌμΆκ°ν©λλ€.
for (int i = 0; i < 256; i++)
for (int j = 0; j < 256; j++)
m_OutImg[i][j] = 255 - m_InImg[i][j];
UpdateAllViews(NULL);
}
Viewμμ μμ
void CWinTestView::OnReaveseView()
{
CWinTestDoc* pDoc = GetDocument(); 2.
//Doc κ° μ£Όκ³ λ°μΌλ €λ©΄ νλ‘μ νΈλͺ
μ λν onDrawμ μλ pDC = getDocument() λ₯Ό κ°μ΄ νμν¨
for (int i = 0; i < 256; i++)
for (int j = 0; j < 256; j++)
pDoc->m_OutImg[i][j] = 255 - pDoc->m_InImg[i][j];
Invalidate(); //νμ¬νλ©΄μ μ§μ°κ³ λ€μκ·Έλ¦Ό
}
//λ°κΈ°
void CMFCApplication3Doc::OnLight_40() //-40
{
// TODO: μ¬κΈ°μ λͺ
λ Ή μ²λ¦¬κΈ° μ½λλ₯Ό μΆκ°ν©λλ€.
for (int i = 0; i < 256; i++)
for (int j = 0; j < 256; j++)
if (m_InImg[i][j] - 40 <= 0) //0~255
m_OutImg[i][j] = 0;
else
m_OutImg[i][j] = m_InImg[i][j] - 40;
UpdateAllViews(NULL);
}
/////////////
void CMFCApplication3View::OnLight30() //+30
{
// TODO: μ¬κΈ°μ λͺ
λ Ή μ²λ¦¬κΈ° μ½λλ₯Ό μΆκ°ν©λλ€.
CMFCApplication3Doc* pDoc = GetDocument();
for (int i = 0; i < 256; i++)
for (int j = 0; j < 256; j++)
if (pDoc->m_InImg[i][j] + 30 > 255) //0~255
pDoc->m_OutImg[i][j] = 255;
else
pDoc->m_OutImg[i][j] = pDoc->m_InImg[i][j] + 30;
Invalidate();
β X 그리기
Viewμμ μμ
void DrawX(CPoint point);
void CMFCApplication1View::DrawX(CPoint point)
{
CClientDC dc(this);
dc.MoveTo(point.x - 10, point.y - 10);
dc.LineTo(point.x + 10, point.y + 10);
dc.MoveTo(point.x - 10, point.y + 10);
dc.LineTo(point.x + 10, point.y - 10);
}
void CMFCApplication2View::OnLButtonDown(UINT nFlags, CPoint point)
{
DrawX(point); // νμΈ
}
Docu.h μ μ μΈ
public:
int m_nCount; //μμ±μμ 0μΌλ‘ μ΄κΈ°ν
CPoint m_ptData[100];
LButtonDownμ μλ μ½λλ‘ λ³κ²½
if (pDoc->m_nCount < 100)
{
pDoc->m_ptData[pDoc->m_nCount] = point
pDoc->m_nCount++;
DrawX(point);
}
Viewμμ μμ
μ§μμ§ λ°©μ§λ₯Ό μν΄ OnDrawμ(λνμμ μ΄λ²€νΈ λ§λ€ λ€μ λ°μ΄ν° κ°μ Έμ΄)
for (int i = 0; i<pDoc->m_nCount; i++)
DrawX(pDoc->m_ptData[i]);
λ°μ΄ν° μ μ₯
void CMFCApplication1Doc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: μ¬κΈ°μμ μ₯μ½λλ₯ΌμΆκ°ν©λλ€.
ar << m_nCount;
for (int i = 0; i < m_nCount; i++)
{
ar << m_ptData[i];
}
}
else
{
// TODO: μ¬κΈ°μλ‘λ©μ½λλ₯ΌμΆκ°ν©λλ€.
ar >> m_nCount;
for (int i = 0; i < m_nCount; i++)
{
ar >> m_ptData[i];
}
}
}